Search in sources :

Example 11 with DependencyPair

use of org.voltdb.DependencyPair in project voltdb by VoltDB.

the class LoadMultipartitionTable method executePlanFragment.

@SuppressWarnings("deprecation")
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    // Return a single long for modified rowcount
    VoltTable result = new VoltTable(new VoltTable.ColumnInfo("", VoltType.BIGINT));
    if (fragmentId == SysProcFragmentId.PF_distribute) {
        assert context.getCluster().getTypeName() != null;
        assert context.getDatabase().getTypeName() != null;
        assert params != null;
        assert params.toArray() != null;
        assert params.toArray()[0] != null;
        assert params.toArray()[1] != null;
        String tableName = (String) params.toArray()[0];
        VoltTable toInsert = (VoltTable) params.toArray()[1];
        // add the partition id
        long currentPartition = context.getPartitionId();
        result.addRow(currentPartition);
        try {
            // voltLoadTable is void. Assume success or exception.
            DeprecatedProcedureAPIAccess.voltLoadTable(this, context.getCluster().getTypeName(), context.getDatabase().getTypeName(), tableName, toInsert, false, false);
            // return the number of rows inserted
            result.addRow(toInsert.getRowCount());
        } catch (VoltAbortException e) {
            // must continue and reply with dependency.
            e.printStackTrace();
            // report -1 rows inserted, though this might be false
            result.addRow(-1);
        }
        return new DependencyPair.TableDependencyPair(DEP_distribute, result);
    } else if (fragmentId == SysProcFragmentId.PF_aggregate) {
        long[] modifiedTuples = new long[context.getNumberOfPartitions()];
        List<VoltTable> deps = dependencies.get(DEP_distribute);
        assert (deps.size() > 0);
        // go through all the deps and find one mod tuple count per partition
        for (VoltTable t : deps) {
            t.advanceRow();
            int partitionId = (int) t.getLong(0);
            t.advanceRow();
            long rowsModified = t.getLong(0);
            if (modifiedTuples[partitionId] == 0) {
                modifiedTuples[partitionId] = rowsModified;
            } else {
                if (modifiedTuples[partitionId] != rowsModified)
                    throw new RuntimeException("@LoadMultipartitionTable received different tuple mod counts from two replicas.");
            }
        }
        // sum up all the modified rows from all partitions
        long rowsModified = 0;
        for (long l : modifiedTuples) rowsModified += l;
        result.addRow(rowsModified);
        return new DependencyPair.TableDependencyPair(DEP_aggregate, result);
    }
    // must handle every dependency id.
    assert (false);
    return null;
}
Also used : List(java.util.List) VoltTable(org.voltdb.VoltTable) DependencyPair(org.voltdb.DependencyPair)

Example 12 with DependencyPair

use of org.voltdb.DependencyPair in project voltdb by VoltDB.

the class ValidatePartitioning method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, final SystemProcedureExecutionContext context) {
    if (fragmentId == SysProcFragmentId.PF_validatePartitioning) {
        final VoltTable results = constructPartitioningResultsTable();
        List<Integer> tableIds = new ArrayList<Integer>();
        List<String> tableNames = new ArrayList<String>();
        for (Table t : CatalogUtil.getNormalTables(context.getDatabase(), false)) {
            tableIds.add(t.getRelativeIndex());
            tableNames.add(t.getTypeName());
        }
        long[] mispartitionedCounts = context.getSiteProcedureConnection().validatePartitioning(Longs.toArray(tableIds), (Integer) params.toArray()[0], (byte[]) params.toArray()[1]);
        for (int ii = 0; ii < tableNames.size(); ii++) {
            results.addRow(context.getHostId(), CoreUtils.getSiteIdFromHSId(context.getSiteId()), context.getPartitionId(), tableNames.get(ii), mispartitionedCounts[ii]);
        }
        return new DependencyPair.TableDependencyPair(DEP_validatePartitioning, results);
    } else if (fragmentId == SysProcFragmentId.PF_validatePartitioningResults) {
        assert (dependencies.size() > 0);
        final VoltTable results = VoltTableUtil.unionTables(dependencies.get(DEP_validatePartitioning));
        return new DependencyPair.TableDependencyPair(DEP_validatePartitioningResults, results);
    } else if (fragmentId == SysProcFragmentId.PF_matchesHashinator) {
        final VoltTable matchesHashinator = constructHashinatorMatchesTable();
        byte[] configBytes = (byte[]) params.toArray()[1];
        if (configBytes == null) {
            configBytes = LegacyHashinator.getConfigureBytes(0);
        }
        final long givenConfigurationSignature = TheHashinator.computeConfigurationSignature(configBytes);
        matchesHashinator.addRow(context.getHostId(), CoreUtils.getSiteIdFromHSId(context.getSiteId()), context.getPartitionId(), givenConfigurationSignature == TheHashinator.getConfigurationSignature() ? (byte) 1 : (byte) 0);
        return new DependencyPair.TableDependencyPair(DEP_matchesHashinator, matchesHashinator);
    } else if (fragmentId == SysProcFragmentId.PF_matchesHashinatorResults) {
        assert (dependencies.size() > 0);
        final VoltTable results = VoltTableUtil.unionTables(dependencies.get(DEP_matchesHashinator));
        return new DependencyPair.TableDependencyPair(DEP_matchesHashinatorResults, results);
    }
    assert (false);
    return null;
}
Also used : Table(org.voltdb.catalog.Table) VoltTable(org.voltdb.VoltTable) ArrayList(java.util.ArrayList) VoltTable(org.voltdb.VoltTable) DependencyPair(org.voltdb.DependencyPair)

Aggregations

DependencyPair (org.voltdb.DependencyPair)12 VoltTable (org.voltdb.VoltTable)9 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)5 ByteBuffer (java.nio.ByteBuffer)2 CatalogContext (org.voltdb.CatalogContext)2 CatalogSpecificPlanner (org.voltdb.CatalogSpecificPlanner)2 SpecifiedException (org.voltdb.exceptions.SpecifiedException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 NavigableSet (java.util.NavigableSet)1 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)1 Stat (org.apache.zookeeper_voltpatches.data.Stat)1 VoltLogger (org.voltcore.logging.VoltLogger)1 DRConsumerDrIdTracker (org.voltdb.DRConsumerDrIdTracker)1 DRLogSegmentId (org.voltdb.DRLogSegmentId)1 ParameterSet (org.voltdb.ParameterSet)1