<commit_before>/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.voltdb.sysprocs.saverestore;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;

import org.json_voltpatches.JSONObject;
import org.voltcore.utils.CoreUtils;
import org.voltcore.utils.InstanceId;
import org.voltcore.utils.Pair;
import org.voltdb.DRLogSegmentId;
import org.voltdb.DefaultSnapshotDataTarget;
import org.voltdb.SnapshotDataFilter;
import org.voltdb.SnapshotDataTarget;
import org.voltdb.SnapshotFormat;
import org.voltdb.SnapshotSiteProcessor;
import org.voltdb.SnapshotTableTask;
import org.voltdb.SystemProcedureExecutionContext;
import org.voltdb.TheHashinator;
import org.voltdb.TheHashinator.HashinatorType;
import org.voltdb.VoltDB;
import org.voltdb.VoltTable;
import org.voltdb.catalog.Table;
import org.voltdb.dtxn.SiteTracker;
import org.voltdb.export.ExportManager;
import org.voltdb.sysprocs.SnapshotRegistry;
import org.voltdb.utils.CatalogUtil;

import com.google_voltpatches.common.collect.Maps;

/**
 * Create a snapshot write plan for a native snapshot.  This will attempt to
 * write every table at every site on every node to disk, with one file per
 * table per node.  Replicated tables are written on every node, but the
 * responsibility for writing them is spread round-robin across the sites on a
 * node.  Partitioned tables are written to the same target per table by every
 * site on a node.
 */
public class NativeSnapshotWritePlan extends SnapshotWritePlan
{
    @Override
    public Callable<Boolean> createSetup(String file_path,
                                            String file_nonce,
                                            long txnId,
                                            Map<Integer, Long> partitionTransactionIds,
                                            Map<Integer, Map<Integer, DRLogSegmentId>> remoteDCLastIds,
                                            JSONObject jsData,
                                            SystemProcedureExecutionContext context,
                                            final VoltTable result,
                                            Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
                                            Map<Integer, DRLogSegmentId> drTupleStreamInfo,
                                            SiteTracker tracker,
                                            HashinatorSnapshotData hashinatorData,
                                            long timestamp)
    {
        return createSetupInternal(file_path, file_nonce, txnId, partitionTransactionIds, remoteDCLastIds,
                jsData, context, result, exportSequenceNumbers, drTupleStreamInfo,
                tracker, hashinatorData, timestamp, context.getNumberOfPartitions());
    }

    Callable<Boolean> createSetupInternal(String file_path,
                                                    String file_nonce,
                                                    long txnId,
                                                    Map<Integer, Long> partitionTransactionIds,
                                                    Map<Integer, Map<Integer, DRLogSegmentId>> remoteDCLastIds,
                                                    JSONObject jsData,
                                                    SystemProcedureExecutionContext context,
                                                    final VoltTable result,
                                                    Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
                                                    Map<Integer, DRLogSegmentId> drTupleStreamInfo,
                                                    SiteTracker tracker,
                                                    HashinatorSnapshotData hashinatorData,
                                                    long timestamp,
                                                    int newPartitionCount)
    {
        assert(SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.isEmpty());

        if (TheHashinator.getConfiguredHashinatorType() == HashinatorType.ELASTIC && hashinatorData == null) {
            throw new RuntimeException("No hashinator data provided for elastic hashinator type.");
        }

        final SnapshotRequestConfig config = new SnapshotRequestConfig(jsData, context.getDatabase());
        final Table[] tableArray;
        if (config.tables.length == 0) {
            tableArray = SnapshotUtil.getTablesToSave(context.getDatabase()).toArray(new Table[0]);
        } else {
            tableArray = config.tables;<commit_msg>ENG-9432: Allow generation of a zero-table native snapshot<commit_after>/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.voltdb.sysprocs.saverestore;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;

import org.json_voltpatches.JSONObject;
import org.voltcore.utils.CoreUtils;
import org.voltcore.utils.InstanceId;
import org.voltcore.utils.Pair;
import org.voltdb.DRLogSegmentId;
import org.voltdb.DefaultSnapshotDataTarget;
import org.voltdb.SnapshotDataFilter;
import org.voltdb.SnapshotDataTarget;
import org.voltdb.SnapshotFormat;
import org.voltdb.SnapshotSiteProcessor;
import org.voltdb.SnapshotTableTask;
import org.voltdb.SystemProcedureExecutionContext;
import org.voltdb.TheHashinator;
import org.voltdb.TheHashinator.HashinatorType;
import org.voltdb.VoltDB;
import org.voltdb.VoltTable;
import org.voltdb.catalog.Table;
import org.voltdb.dtxn.SiteTracker;
import org.voltdb.export.ExportManager;
import org.voltdb.sysprocs.SnapshotRegistry;
import org.voltdb.utils.CatalogUtil;

import com.google_voltpatches.common.collect.Maps;

/**
 * Create a snapshot write plan for a native snapshot.  This will attempt to
 * write every table at every site on every node to disk, with one file per
 * table per node.  Replicated tables are written on every node, but the
 * responsibility for writing them is spread round-robin across the sites on a
 * node.  Partitioned tables are written to the same target per table by every
 * site on a node.
 */
public class NativeSnapshotWritePlan extends SnapshotWritePlan
{
    @Override
    public Callable<Boolean> createSetup(String file_path,
                                            String file_nonce,
                                            long txnId,
                                            Map<Integer, Long> partitionTransactionIds,
                                            Map<Integer, Map<Integer, DRLogSegmentId>> remoteDCLastIds,
                                            JSONObject jsData,
                                            SystemProcedureExecutionContext context,
                                            final VoltTable result,
                                            Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
                                            Map<Integer, DRLogSegmentId> drTupleStreamInfo,
                                            SiteTracker tracker,
                                            HashinatorSnapshotData hashinatorData,
                                            long timestamp)
    {
        return createSetupInternal(file_path, file_nonce, txnId, partitionTransactionIds, remoteDCLastIds,
                jsData, context, result, exportSequenceNumbers, drTupleStreamInfo,
                tracker, hashinatorData, timestamp, context.getNumberOfPartitions());
    }

    Callable<Boolean> createSetupInternal(String file_path,
                                                    String file_nonce,
                                                    long txnId,
                                                    Map<Integer, Long> partitionTransactionIds,
                                                    Map<Integer, Map<Integer, DRLogSegmentId>> remoteDCLastIds,
                                                    JSONObject jsData,
                                                    SystemProcedureExecutionContext context,
                                                    final VoltTable result,
                                                    Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
                                                    Map<Integer, DRLogSegmentId> drTupleStreamInfo,
                                                    SiteTracker tracker,
                                                    HashinatorSnapshotData hashinatorData,
                                                    long timestamp,
                                                    int newPartitionCount)
    {
        assert(SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.isEmpty());

        if (TheHashinator.getConfiguredHashinatorType() == HashinatorType.ELASTIC && hashinatorData == null) {
            throw new RuntimeException("No hashinator data provided for elastic hashinator type.");
        }

        final SnapshotRequestConfig config = new SnapshotRequestConfig(jsData, context.getDatabase());
        final Table[] tableArray;
        if (config.tables.length == 0 && !jsData.has("tables")) {
            tableArray = SnapshotUtil.getTablesToSave(context.getDatabase()).toArray(new Table[0]);
        } else {
            tableArray = config.tables;
{'fraction_non_alphanumeric': 0.06203586306828473, 'fraction_numerical': 0.00235464589748234, 'mean_word_length': 1.867566865749156, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 100, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '535280', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2410, 'n_words': 751}