Beispiel #1
0
  public VoltTable[] run(long phoneNumber, int contestantNumber, long maxVotesPerPhoneNumber) {
    VoltTable result =
        new VoltTable(
            new ColumnInfo("STATUS", VoltType.BIGINT), new ColumnInfo("REJECTED", VoltType.BIGINT));

    // Queue up validation statements
    voltQueueSQL(checkContestantStmt, EXPECT_ZERO_OR_ONE_ROW, contestantNumber);
    voltQueueSQL(checkVoterStmt, EXPECT_ZERO_OR_ONE_ROW, phoneNumber);
    voltQueueSQL(checkStateStmt, EXPECT_ZERO_OR_ONE_ROW, (short) (phoneNumber / 10000000l));
    voltQueueSQL(checkRejectedVotesStmt, EXPECT_ZERO_OR_ONE_ROW, phoneNumber);
    VoltTable validation[] = voltExecuteSQL();

    if (validation[0].getRowCount() == 0) {
      result.addRow(ERR_INVALID_CONTESTANT, -1);
      return new VoltTable[] {result};
    }

    // Get rejected votes
    long rejectedVotes = 1;
    if (validation[3].getRowCount() == 1) {
      rejectedVotes = validation[3].asScalarLong() + 1;
    }

    if ((validation[1].getRowCount() == 1)
        && (validation[1].asScalarLong() >= maxVotesPerPhoneNumber)) {
      if (validation[3].getRowCount() == 1) {
        // Increment count
        voltQueueSQL(incrementRejectedVotesStmt, phoneNumber);
      } else {
        // insert
        voltQueueSQL(insertRejectedVotesStmt, phoneNumber, 1);
      }
      voltExecuteSQL();

      result.addRow(ERR_VOTER_OVER_VOTE_LIMIT, rejectedVotes);
      return new VoltTable[] {result};
    }

    // Some sample client libraries use the legacy random phone generation that mostly
    // created invalid phone numbers. Until refactoring, re-assign all such votes to
    // the "XX" fake state (those votes will not appear on the Live Statistics dashboard,
    // but are tracked as legitimate instead of invalid, as old clients would mostly get
    // it wrong and see all their transactions rejected).
    final String state =
        (validation[2].getRowCount() > 0) ? validation[2].fetchRow(0).getString(0) : "XX";

    // Post the vote
    voltQueueSQL(insertVoteStmt, EXPECT_SCALAR_MATCH(1), phoneNumber, state, contestantNumber);
    voltExecuteSQL(true);

    // Set the return value to 0: successful vote
    result.addRow(VOTE_SUCCESSFUL, rejectedVotes);
    return new VoltTable[] {result};
  }
  /** Save the profile information into the database */
  protected final void saveProfile(BenchmarkComponent baseClient) {

    // CONFIG_PROFILE
    Table catalog_tbl =
        catalogContext.database.getTables().get(SEATSConstants.TABLENAME_CONFIG_PROFILE);
    VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
    assert (vt != null);
    vt.addRow(
        this.scale_factor, // CFP_SCALE_FACTOR
        this.airport_max_customer_id.toJSONString(), // CFP_AIPORT_MAX_CUSTOMER
        this.flight_start_date, // CFP_FLIGHT_START
        this.flight_upcoming_date, // CFP_FLIGHT_UPCOMING
        this.flight_past_days, // CFP_FLIGHT_PAST_DAYS
        this.flight_future_days, // CFP_FLIGHT_FUTURE_DAYS
        this.num_flights, // CFP_NUM_FLIGHTS
        this.num_customers, // CFP_NUM_CUSTOMERS
        this.num_reservations, // CFP_NUM_RESERVATIONS
        JSONUtil.toJSONString(this.code_id_xref) // CFP_CODE_ID_XREF
        );
    if (debug.val)
      LOG.debug(String.format("Saving profile information into %s\n%s", catalog_tbl, this));
    baseClient.loadVoltTable(catalog_tbl.getName(), vt);

    // CONFIG_HISTOGRAMS
    catalog_tbl =
        catalogContext.database.getTables().get(SEATSConstants.TABLENAME_CONFIG_HISTOGRAMS);
    vt = CatalogUtil.getVoltTable(catalog_tbl);
    assert (vt != null);

    for (Entry<String, Histogram<String>> e : this.airport_histograms.entrySet()) {
      vt.addRow(
          e.getKey(), // CFH_NAME
          e.getValue().toJSONString(), // CFH_DATA
          1 // CFH_IS_AIRPORT
          );
    } // FOR
    if (debug.val) LOG.debug("Saving airport histogram information into " + catalog_tbl);
    baseClient.loadVoltTable(catalog_tbl.getName(), vt);

    for (Entry<String, Histogram<String>> e : this.histograms.entrySet()) {
      vt.addRow(
          e.getKey(), // CFH_NAME
          e.getValue().toJSONString(), // CFH_DATA
          0 // CFH_IS_AIRPORT
          );
    } // FOR
    if (debug.val) LOG.debug("Saving benchmark histogram information into " + catalog_tbl);
    baseClient.loadVoltTable(catalog_tbl.getName(), vt);

    return;
  }
  @Override
  public void setUp() {
    m_voltdb = new MockVoltDB();
    VoltDB.replaceVoltDBInstanceForTest(m_voltdb);

    VoltTable.ColumnInfo[] cols1 = {new VoltTable.ColumnInfo("name", VoltType.STRING)};

    VoltTable.ColumnInfo[] cols2 = {new VoltTable.ColumnInfo("age", VoltType.INTEGER)};

    t1 = new VoltTable(cols1, 1);
    t1.addRow("dude");
    t2 = new VoltTable(cols2, 1);
    t2.addRow(10);
  }
  public void testReplicaDependencyWithMismatchedResults() {
    VoltTable.ColumnInfo[] cols2 = {new VoltTable.ColumnInfo("age", VoltType.INTEGER)};

    VoltTable t3 = new VoltTable(cols2, 1);
    t3.addRow(11);

    setUpSites(2, 2, 1);
    int multi_dep = 5 | DtxnConstants.MULTIPARTITION_DEPENDENCY;
    WorkUnit w =
        new WorkUnit(
            m_voltdb.getCatalogContext().siteTracker,
            work,
            new int[] {4, multi_dep},
            0,
            new int[] {1, 2, 3},
            false);
    assertFalse(w.allDependenciesSatisfied());
    assertEquals(w.getDependency(4).size(), 0);
    assertEquals(w.getDependency(5).size(), 0);
    w.putDependency(4, 0, t1);
    assertFalse(w.allDependenciesSatisfied());
    w.putDependency(multi_dep, 0, t2);
    assertFalse(w.allDependenciesSatisfied());
    boolean threw = false;
    try {
      w.putDependency(multi_dep, 1, t3);
    } catch (RuntimeException e) {
      threw = true;
    }
    assertTrue(threw);
  }
Beispiel #5
0
  public VoltTable[] run(int precision, String tag) {
    if (tag == null || tag.length() == 0) {
      voltQueueSQL(resultStmt);
    } else {
      voltQueueSQL(resultByTagStmt, tag);
    }

    VoltTable[] raw = voltExecuteSQL(true);

    if (precision == 1) return raw;

    final VoltTable result =
        new VoltTable(
            new VoltTable.ColumnInfo("lat", VoltType.SMALLINT),
            new VoltTable.ColumnInfo("lon", VoltType.SMALLINT),
            new VoltTable.ColumnInfo("record_count", VoltType.BIGINT),
            new VoltTable.ColumnInfo("tag", VoltType.STRING));

    final HashMap<String, Long> map = new HashMap<String, Long>();
    while (raw[0].advanceRow()) {
      final String key =
          (raw[0].getLong(0) / (long) precision) * (long) precision
              + ":"
              + (raw[0].getLong(1) / (long) precision) * (long) precision;
      if (map.containsKey(key)) map.put(key, (long) map.get(key) + raw[0].getLong(2));
      else map.put(key, raw[0].getLong(2));
    }
    for (String key : map.keySet()) {
      String[] keyParts = key.split(":");
      result.addRow(
          Short.parseShort(keyParts[0]), Short.parseShort(keyParts[1]), (long) map.get(key), tag);
    }
    return new VoltTable[] {result};
  }
  public VoltTable[] run(long f_id) {
    final boolean debug = LOG.isDebugEnabled();

    // Empty seats bitmap
    final long seatmap[] = new long[SEATSConstants.FLIGHTS_NUM_SEATS];
    Arrays.fill(seatmap, -1);

    voltQueueSQL(GetFlight, f_id);
    voltQueueSQL(GetSeats, f_id);
    final VoltTable[] results = voltExecuteSQL(true);
    assert (results.length == 2);

    // First calculate the seat price using the flight's base price
    // and the number of seats that remaining
    if (results[0].advanceRow() == false) {
      throw new VoltAbortException(
          ErrorType.INVALID_FLIGHT_ID + String.format(" Invalid flight #%d", f_id));
    }

    int col = 6;
    double base_price = results[0].getDouble(col++); // F_BASE_PRICE
    long seats_total = results[0].getLong(col++); // F_SEATS_TOTAL
    long seats_left = results[0].getLong(col++); // F_SEATS_LEFT
    double seat_price = results[0].getDouble(col++); // MATHS!

    if (debug) {
      // TODO: Figure out why this doesn't match the SQL
      double _seat_price = base_price + (base_price * (1.0 - (seats_left / (double) seats_total)));
      LOG.debug(
          String.format(
              "Flight %d - SQL[%.2f] <-> JAVA[%.2f] [basePrice=%f, total=%d, left=%d]",
              f_id, seat_price, _seat_price, base_price, seats_total, seats_left));
    }

    // Then build the seat map of the remaining seats
    while (results[1].advanceRow()) {
      long r_id = results[1].getLong(0);
      int seatnum = (int) results[1].getLong(2);
      if (debug) LOG.debug(String.format("ROW fid %d rid %d seat %d", f_id, r_id, seatnum));
      assert (seatmap[seatnum] == -1) : "Duplicate seat reservation: R_ID=" + r_id;
      seatmap[seatnum] = 1; // results[1].getLong(1);
    } // WHILE

    int ctr = 0;
    VoltTable returnResults = new VoltTable(outputColumns);
    for (int i = 0; i < seatmap.length; ++i) {
      if (seatmap[i] == -1) {
        Object[] row = new Object[] {f_id, i, seat_price};
        returnResults.addRow(row);
        if (ctr == SEATSConstants.FLIGHTS_NUM_SEATS) break;
      }
    } // FOR
    //        assert(seats_left == returnResults.getRowCount()) :
    //            String.format("Flight %d - Expected[%d] != Actual[%d]", f_id, seats_left,
    // returnResults.getRowCount());

    if (debug) LOG.debug(String.format("Flight %d Open Seats:\n%s", f_id, returnResults));
    return new VoltTable[] {results[0], returnResults};
  }
Beispiel #7
0
  /** Populate Subscriber table per benchmark spec. */
  void genSubscriber(Table catalog_tbl) {
    final VoltTable table = CatalogUtil.getVoltTable(catalog_tbl);
    Object row[] = new Object[table.getColumnCount()];
    long total = 0;
    for (long s_id = 0; s_id < this.subscriberSize; s_id++) {
      int col = 0;
      row[col++] = s_id;
      row[col++] = TM1Util.padWithZero(s_id);

      // BIT_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 1);
      } // FOR
      // HEX_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 15);
      }
      // BYTE2_##
      for (int j = 0; j < 10; j++) {
        row[col++] = TM1Util.number(0, 255);
      }
      // MSC_LOCATION + VLR_LOCATION
      for (int j = 0; j < 2; j++) {
        row[col++] = TM1Util.number(0, Integer.MAX_VALUE);
      }
      assert col == table.getColumnCount();
      table.addRow(row);
      total++;

      if (table.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d)
          LOG.debug(
              String.format(
                  "%s: %6d / %d", TM1Constants.TABLENAME_SUBSCRIBER, total, this.subscriberSize));
        loadVoltTable(TM1Constants.TABLENAME_SUBSCRIBER, table);
        table.clearRowData();
        assert (table.getRowCount() == 0);
      }
    } // FOR
    if (table.getRowCount() > 0) {
      if (d)
        LOG.debug(
            String.format(
                "%s: %6d / %d", TM1Constants.TABLENAME_SUBSCRIBER, total, this.subscriberSize));
      loadVoltTable(TM1Constants.TABLENAME_SUBSCRIBER, table);
      table.clearRowData();
      assert (table.getRowCount() == 0);
    }
  }
Beispiel #8
0
  /**
   * Exit admin mode
   *
   * @param ctx Internal parameter. Not user-accessible.
   * @return Standard STATUS table.
   */
  public VoltTable[] run(SystemProcedureExecutionContext ctx) {
    // Choose the lowest site ID on this host to actually flip the bit
    if (ctx.isLowestSiteId()) {
      VoltDB.instance().setMode(OperationMode.RUNNING);
      try {
        VoltDB.instance()
            .getHostMessenger()
            .getZK()
            .setData(VoltZK.operationMode, OperationMode.RUNNING.toString().getBytes("UTF-8"), -1);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
    t.addRow(VoltSystemProcedure.STATUS_OK);
    return (new VoltTable[] {t});
  }
  @Override
  public String formatFinalResults(BenchmarkResults br) {
    if (this.stop) return (null);

    VoltTable vt = new VoltTable(COLUMNS);
    for (Object row[] : this.results) {
      vt.addRow(row);
    }

    try {
      FileWriter writer = new FileWriter(this.outputPath);
      VoltTableUtil.csv(writer, vt, true);
      writer.close();
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    LOG.info("Wrote CSV results to '" + this.outputPath.getAbsolutePath() + "'");
    return (null);
  }
  public VoltTable[] run() {
    voltQueueSQL(resultStmt);
    VoltTable[] results1 = voltExecuteSQL(true);
    VoltTable t = results1[0];

    VoltTable t2 =
        new VoltTable(
            new VoltTable.ColumnInfo("rank", VoltType.INTEGER),
            new VoltTable.ColumnInfo("contestant_name", VoltType.STRING),
            new VoltTable.ColumnInfo("contestant_number", VoltType.INTEGER),
            new VoltTable.ColumnInfo("num_votes_expr", VoltType.BIGINT));

    int rank = 0;
    while (t.advanceRow()) {
      t2.addRow(
          new Object[] {rank++, t.getString(0), (int) t.getLong(1), (long) (t.getLong(2) + 10)});
    }

    return new VoltTable[] {t2};
  }
  private void loadData(Table catalog_tbl) throws Exception {
    // Load in a bunch of dummy data for this table
    VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
    assertNotNull(vt);
    for (int i = 0; i < NUM_TUPLES; i++) {
      Object row[] = VoltTableUtil.getRandomRow(catalog_tbl);

      if (catalog_tbl.getName().equalsIgnoreCase(TPCCConstants.TABLENAME_ORDER_LINE)) {
        row[0] = i; // OL_O_ID
        row[1] = (byte) i; // OL_D_ID
        row[2] = (short) i; // OL_W_ID
      }
      vt.addRow(row);
    } // FOR
    this.executor.loadTable(1000l, catalog_tbl, vt, false);

    int statsLocators[] = {catalog_tbl.getRelativeIndex()};
    VoltTable stats[] = this.ee.getStats(SysProcSelector.TABLE, statsLocators, false, 0L);
    assertEquals(1, stats.length);
    // System.err.println(VoltTableUtil.format(stats));
  }
 public VoltTable run(int contestantNumber, int max) {
   ArrayList<Result> results = new ArrayList<Result>();
   voltQueueSQL(resultStmt);
   VoltTable summary = voltExecuteSQL()[0];
   String state = "";
   while (summary.advanceRow()) {
     if (!summary.getString(1).equals(state)) {
       state = summary.getString(1);
       if (summary.getLong(0) == contestantNumber)
         results.add(new Result(state, summary.getLong(2)));
     }
   }
   Result[] resultArray = (Result[]) results.toArray();
   Arrays.sort(resultArray, new OrderByVotesDesc());
   VoltTable result =
       new VoltTable(
           new VoltTable.ColumnInfo("state", VoltType.STRING),
           new VoltTable.ColumnInfo("num_votes", VoltType.BIGINT));
   for (int i = 0; i < Math.min(resultArray.length, max); i++)
     result.addRow(new Object[] {resultArray[i].state, resultArray[i].votes});
   return result;
 }
  public VoltTable[] run(short w_id, byte d_id, byte[] c_last) {
    voltQueueSQL(getCustomersByLastName, w_id, d_id, c_last);
    VoltTable customers = voltExecuteSQL()[0];

    // Get the midpoint customer's id
    final int namecnt = customers.getRowCount();
    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final long c_id = customer.getLong(C_ID_IDX);

    // Build an VoltTable with a single customer row
    final VoltTable customerResultTable = result_template.clone(1024);
    customerResultTable.addRow(
        c_id,
        customer.getStringAsBytes(1),
        customer.getStringAsBytes(2),
        customer.getStringAsBytes(3),
        customer.getDouble(4));

    // Do the rest of the work
    return getOrderStatus(w_id, d_id, c_id, customerResultTable);
  }
  @Override
  public Callable<Boolean> createSetup(
      String file_path,
      String file_nonce,
      long txnId,
      Map<Integer, Long> partitionTransactionIds,
      JSONObject jsData,
      SystemProcedureExecutionContext context,
      VoltTable result,
      Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
      SiteTracker tracker,
      HashinatorSnapshotData hashinatorData,
      long timestamp) {
    assert SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.isEmpty();

    final IndexSnapshotRequestConfig config =
        new IndexSnapshotRequestConfig(jsData, context.getDatabase());
    final Map<Integer, Long> pidToLocalHSIds = findLocalSources(config.partitionRanges, tracker);

    // mark snapshot start in registry
    final AtomicInteger numTables = new AtomicInteger(config.tables.length);
    m_snapshotRecord =
        SnapshotRegistry.startSnapshot(
            txnId, context.getHostId(), file_path, file_nonce, SnapshotFormat.INDEX, config.tables);

    // create table tasks
    for (Table table : config.tables) {
      createTasksForTable(
          table, config.partitionRanges, pidToLocalHSIds, numTables, m_snapshotRecord);
      result.addRow(
          context.getHostId(),
          CoreUtils.getHostnameOrAddress(),
          table.getTypeName(),
          "SUCCESS",
          "");
    }

    return null;
  }
Beispiel #15
0
  /** Populate Access_Info table per benchmark spec. */
  void genAccessInfo(Table catalog_tbl) {
    final VoltTable table = CatalogUtil.getVoltTable(catalog_tbl);
    int[] arr = {1, 2, 3, 4};

    int[] ai_types = TM1Util.subArr(arr, 1, 4);
    long total = 0;
    for (long s_id = 0; s_id < this.subscriberSize; s_id++) {
      for (int ai_type : ai_types) {
        Object row[] = new Object[table.getColumnCount()];
        row[0] = s_id;
        row[1] = ai_type;
        row[2] = TM1Util.number(0, 255);
        row[3] = TM1Util.number(0, 255);
        row[4] = TM1Util.astring(3, 3);
        row[5] = TM1Util.astring(5, 5);
        table.addRow(row);
        total++;
      } // FOR
      if (table.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d)
          LOG.debug(
              String.format(
                  "%s: %6d / %d",
                  TM1Constants.TABLENAME_ACCESS_INFO, total, ai_types.length * subscriberSize));
        loadVoltTable(TM1Constants.TABLENAME_ACCESS_INFO, table);
        table.clearRowData();
      }
    } // WHILE
    if (table.getRowCount() > 0) {
      if (d)
        LOG.debug(
            String.format(
                "%s: %6d / %d",
                TM1Constants.TABLENAME_ACCESS_INFO, total, ai_types.length * subscriberSize));
      loadVoltTable(TM1Constants.TABLENAME_ACCESS_INFO, table);
      table.clearRowData();
    }
  }
  protected boolean createSetupInternal(
      String file_path,
      String file_nonce,
      long txnId,
      Map<Integer, Long> partitionTransactionIds,
      JSONObject jsData,
      SystemProcedureExecutionContext context,
      String hostname,
      final VoltTable result,
      Map<String, Map<Integer, Pair<Long, Long>>> exportSequenceNumbers,
      SiteTracker tracker,
      long timestamp)
      throws IOException {
    assert (SnapshotSiteProcessor.ExecutionSitesCurrentlySnapshotting.isEmpty());

    /*
     * List of partitions to include if this snapshot is
     * going to be deduped. Attempts to break up the work
     * by seeding and RNG selecting
     * a random replica to do the work. Will not work in failure
     * cases, but we don't use dedupe when we want durability.
     */
    List<Long> sitesToInclude = CSVSnapshotWritePlan.computeDedupedLocalSites(txnId, tracker);
    // If there's no work to do on this host, just claim success and get out:
    if (sitesToInclude.isEmpty() && !tracker.isFirstHost()) {
      return false;
    }

    NativeSnapshotWritePlan.createFileBasedCompletionTasks(
        file_path,
        file_nonce,
        txnId,
        partitionTransactionIds,
        context,
        exportSequenceNumbers,
        timestamp);

    final List<Table> tables = SnapshotUtil.getTablesToSave(context.getDatabase());
    final AtomicInteger numTables = new AtomicInteger(tables.size());
    final SnapshotRegistry.Snapshot snapshotRecord =
        SnapshotRegistry.startSnapshot(
            txnId,
            context.getHostId(),
            file_path,
            file_nonce,
            SnapshotFormat.CSV,
            tables.toArray(new Table[0]));

    SnapshotDataTarget sdt = null;
    boolean noTargetsCreated = true;

    final ArrayList<SnapshotTableTask> partitionedSnapshotTasks =
        new ArrayList<SnapshotTableTask>();
    final ArrayList<SnapshotTableTask> replicatedSnapshotTasks = new ArrayList<SnapshotTableTask>();
    for (final Table table : tables) {
      /*
       * For a deduped csv snapshot, only produce the replicated tables on the "leader"
       * host.
       */
      if (table.getIsreplicated() && !tracker.isFirstHost()) {
        snapshotRecord.removeTable(table.getTypeName());
        continue;
      }

      File saveFilePath = null;
      saveFilePath =
          SnapshotUtil.constructFileForTable(
              table, file_path, file_nonce, SnapshotFormat.CSV, context.getHostId());

      try {
        sdt = new SimpleFileSnapshotDataTarget(saveFilePath, !table.getIsreplicated());

        m_targets.add(sdt);
        final Runnable onClose =
            new TargetStatsClosure(sdt, table.getTypeName(), numTables, snapshotRecord);
        sdt.setOnCloseHandler(onClose);

        List<SnapshotDataFilter> filters = new ArrayList<SnapshotDataFilter>();
        filters.add(new CSVSnapshotFilter(CatalogUtil.getVoltTable(table), ',', null));

        final SnapshotTableTask task =
            new SnapshotTableTask(
                table.getRelativeIndex(),
                sdt,
                filters.toArray(new SnapshotDataFilter[filters.size()]),
                table.getIsreplicated(),
                table.getTypeName());

        if (table.getIsreplicated()) {
          replicatedSnapshotTasks.add(task);
        } else {
          partitionedSnapshotTasks.add(task);
        }

        noTargetsCreated = false;
        result.addRow(context.getHostId(), hostname, table.getTypeName(), "SUCCESS", "");
      } catch (IOException ex) {
        handleTargetCreationError(
            sdt, context, file_nonce, hostname, table.getTypeName(), ex, result);
      }
    }

    if (noTargetsCreated) {
      SnapshotRegistry.discardSnapshot(snapshotRecord);
    }

    // CSV snapshots do the partitioned work only on the specified sites for de-duping,
    // but since we've pre-filtered the replicated task list to only contain entries on
    // one node, we can go ahead and distribute them across all of the sites on that node.
    placePartitionedTasks(partitionedSnapshotTasks, sitesToInclude);
    placeReplicatedTasks(replicatedSnapshotTasks, tracker.getSitesForHost(context.getHostId()));
    return noTargetsCreated;
  }
Beispiel #17
0
  @Override
  public DependencySet executePlanFragment(
      Long txn_id,
      Map<Integer, List<VoltTable>> dependencies,
      int fragmentId,
      ParameterSet params,
      PartitionExecutor.SystemProcedureExecutionContext context) {
    DependencySet result = null;
    switch (fragmentId) {
        // Reset Stats
      case SysProcFragmentId.PF_resetProfilingDistribute:
        {
          LOG.debug("Resetting internal profiling counters");
          HStoreConf hstore_conf = hstore_site.getHStoreConf();

          PartitionExecutor.Debug executorDebug = this.executor.getDebugContext();

          // EXECUTOR
          if (hstore_conf.site.exec_profiling) {
            executorDebug.getProfiler().reset();
          }

          // SPEC EXEC
          if (hstore_conf.site.specexec_profiling) {
            Collection<SpecExecProfiler> profilers =
                executorDebug.getSpecExecScheduler().getDebugContext().getProfilers().values();
            for (SpecExecProfiler profiler : profilers) {
              profiler.reset();
            } // FOR
          }

          // MARKOV
          if (hstore_conf.site.markov_profiling) {
            TransactionEstimator est = executor.getTransactionEstimator();
            if (est instanceof MarkovEstimator) {
              ((MarkovEstimator) est).getDebugContext().getProfiler().reset();
            }
          }

          // QUEUE
          if (hstore_conf.site.queue_profiling) {
            TransactionQueueManagerProfiler profiler =
                hstore_site
                    .getTransactionQueueManager()
                    .getDebugContext()
                    .getProfiler(this.partitionId);
            profiler.reset();
          }

          // The first partition at this HStoreSite will have to reset
          // any global profling parameters
          if (this.isFirstLocalPartition()) {
            // COMMAND LOGGER
            CommandLogWriter commandLog = hstore_site.getCommandLogWriter();
            if (hstore_conf.site.commandlog_profiling && commandLog.getProfiler() != null) {
              commandLog.getProfiler().reset();
            }
          }

          VoltTable vt = new VoltTable(nodeResultsColumns);
          vt.addRow(
              this.executor.getHStoreSite().getSiteName(),
              this.gcTime.getTotalThinkTimeMS() + " ms",
              new TimestampType());
          result = new DependencySet(SysProcFragmentId.PF_resetProfilingDistribute, vt);
          break;
        }
        // Aggregate Results
      case SysProcFragmentId.PF_resetProfilingAggregate:
        List<VoltTable> siteResults =
            dependencies.get(SysProcFragmentId.PF_resetProfilingDistribute);
        if (siteResults == null || siteResults.isEmpty()) {
          String msg = "Missing site results";
          throw new ServerFaultException(msg, txn_id);
        }

        VoltTable vt = VoltTableUtil.union(siteResults);
        result = new DependencySet(SysProcFragmentId.PF_resetProfilingAggregate, vt);
        break;
      default:
        String msg = "Unexpected sysproc fragmentId '" + fragmentId + "'";
        throw new ServerFaultException(msg, txn_id);
    } // SWITCH
    // Invalid!
    return (result);
  }
Beispiel #18
0
  /** Populate Special_Facility table and CallForwarding table per benchmark spec. */
  void genSpeAndCal(Table catalog_spe, Table catalog_cal) {
    VoltTable speTbl = CatalogUtil.getVoltTable(catalog_spe);
    VoltTable calTbl = CatalogUtil.getVoltTable(catalog_cal);

    long speTotal = 0;
    long calTotal = 0;
    int[] arrSpe = {1, 2, 3, 4};
    int[] arrCal = {0, 8, 6};

    for (long s_id = 0; s_id < this.subscriberSize; s_id++) {
      int[] sf_types = TM1Util.subArr(arrSpe, 1, 4);
      for (int sf_type : sf_types) {
        Object row_spe[] = new Object[speTbl.getColumnCount()];
        row_spe[0] = s_id;
        row_spe[1] = sf_type;
        row_spe[2] = TM1Util.isActive();
        row_spe[3] = TM1Util.number(0, 255);
        row_spe[4] = TM1Util.number(0, 255);
        row_spe[5] = TM1Util.astring(5, 5);
        speTbl.addRow(row_spe);
        speTotal++;

        // now call_forwarding
        int[] start_times = TM1Util.subArr(arrCal, 0, 3);
        for (int start_time : start_times) {
          Object row_cal[] = new Object[calTbl.getColumnCount()];
          row_cal[0] = s_id;
          row_cal[1] = sf_type;
          row_cal[2] = start_time;
          row_cal[3] = start_time + TM1Util.number(1, 8);
          row_cal[4] = TM1Util.nstring(15, 15);
          calTbl.addRow(row_cal);
          calTotal++;
        } // FOR
      } // FOR

      if (calTbl.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d) LOG.debug(String.format("%s: %d", TM1Constants.TABLENAME_CALL_FORWARDING, calTotal));
        loadVoltTable(TM1Constants.TABLENAME_CALL_FORWARDING, calTbl);
        calTbl.clearRowData();
        assert (calTbl.getRowCount() == 0);
      }
      if (speTbl.getRowCount() >= TM1Constants.BATCH_SIZE) {
        if (d)
          LOG.debug(String.format("%s: %d", TM1Constants.TABLENAME_SPECIAL_FACILITY, speTotal));
        loadVoltTable(TM1Constants.TABLENAME_SPECIAL_FACILITY, speTbl);
        speTbl.clearRowData();
        assert (speTbl.getRowCount() == 0);
      }
    } // WHILE
    if (calTbl.getRowCount() > 0) {
      if (d) LOG.debug(String.format("%s: %d", TM1Constants.TABLENAME_CALL_FORWARDING, calTotal));
      loadVoltTable(TM1Constants.TABLENAME_CALL_FORWARDING, calTbl);
      calTbl.clearRowData();
      assert (calTbl.getRowCount() == 0);
    }
    if (speTbl.getRowCount() > 0) {
      if (d) LOG.debug(String.format("%s: %d", TM1Constants.TABLENAME_SPECIAL_FACILITY, speTotal));
      loadVoltTable(TM1Constants.TABLENAME_SPECIAL_FACILITY, speTbl);
      speTbl.clearRowData();
      assert (speTbl.getRowCount() == 0);
    }
  }
Beispiel #19
0
  public VoltTable run(short w_id, int o_carrier_id, TimestampType timestamp)
      throws VoltAbortException {
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      voltQueueSQL(getNewOrder, d_id, w_id);
    }
    final VoltTable[] neworderresults = voltExecuteSQL();
    assert neworderresults.length == Constants.DISTRICTS_PER_WAREHOUSE;
    final Long[] no_o_ids = new Long[Constants.DISTRICTS_PER_WAREHOUSE];
    int valid_neworders = 0;
    int[] result_offsets = new int[Constants.DISTRICTS_PER_WAREHOUSE];
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      final VoltTable newOrder = neworderresults[(int) d_id - 1];

      if (newOrder.getRowCount() == 0) {
        // No orders for this district: skip it. Note: This must be reported if > 1%
        result_offsets[(int) d_id - 1] = -1;
        continue;
      }
      assert newOrder.getRowCount() == 1;

      result_offsets[(int) d_id - 1] = valid_neworders * 2;
      ++valid_neworders;
      final Long no_o_id = newOrder.asScalarLong();
      no_o_ids[(int) d_id - 1] = no_o_id;
      voltQueueSQL(getCId, no_o_id, d_id, w_id);
      voltQueueSQL(sumOLAmount, no_o_id, d_id, w_id);
    }
    final VoltTable[] otherresults = voltExecuteSQL();
    assert otherresults.length == valid_neworders * 2;

    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      final VoltTable newOrder = neworderresults[(int) d_id - 1];

      if (newOrder.getRowCount() == 0) {
        // No orders for this district: skip it. Note: This must be reported if > 1%
        continue;
      }
      assert newOrder.getRowCount() == 1;

      final Long no_o_id = newOrder.asScalarLong();
      no_o_ids[(int) d_id - 1] = no_o_id;
      voltQueueSQL(deleteNewOrder, d_id, w_id, no_o_id);
      voltQueueSQL(updateOrders, o_carrier_id, no_o_id, d_id, w_id);
      voltQueueSQL(updateOrderLine, timestamp, no_o_id, d_id, w_id);
    }
    voltExecuteSQL();

    // these must be logged in the "result file" according to TPC-C 2.7.2.2 (page 39)
    // We remove the queued time, completed time, w_id, and o_carrier_id: the client can figure
    // them out
    final VoltTable result = result_template.clone(1024);
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      int resultoffset = result_offsets[(int) d_id - 1];

      if (resultoffset < 0) {
        continue;
      }
      assert otherresults[resultoffset + 0].getRowCount() == 1;
      assert otherresults[resultoffset + 1].getRowCount() == 1;
      final long c_id = (otherresults[resultoffset + 0].asScalarLong());
      final VoltTableRow row = otherresults[resultoffset + 1].fetchRow(0);
      final double ol_total = row.getDouble(0);
      final boolean ol_total_wasnull = row.wasNull();

      // If there are no order lines, SUM returns null. There should always be order lines.
      if (ol_total_wasnull) {
        throw new VoltAbortException(
            "ol_total is NULL: there are no order lines. This should not happen");
      }
      assert ol_total > 0.0;

      voltQueueSQL(updateCustomer, ol_total, c_id, d_id, w_id);

      final Long no_o_id = no_o_ids[(int) d_id - 1];
      result.addRow(d_id, no_o_id);
    }
    voltExecuteSQL();

    return result;
  }
Beispiel #20
0
  public VoltTable[] run(long zip) throws VoltAbortException {
    Date timestamp = new Date();

    // create a District, Warehouse, and 4 Customers (multiple, since we
    // want to test for correct behavior of paymentByCustomerName.

    final double initialYTD = 15241.45;
    voltQueueSQL(
        insertDistrict,
        7L,
        3L,
        "A District",
        "Street Addy",
        "meh",
        "westerfield",
        "BA",
        "99999",
        .0825,
        initialYTD,
        21L);
    // check that a district was inserted
    long resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    voltQueueSQL(
        insertWarehouse,
        3L,
        "EZ Street WHouse",
        "Headquarters",
        "77 Mass. Ave.",
        "Cambridge",
        "AZ",
        "12938",
        .1234,
        initialYTD);
    // check that a warehouse was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    final double initialBalance = 15.75;
    voltQueueSQL(
        insertCustomer,
        C_ID,
        D_ID,
        W_ID,
        "I",
        "Be",
        "lastname",
        "Place",
        "Place2",
        "BiggerPlace",
        "AL",
        "91083",
        "(193) 099 - 9082",
        new Date(),
        "BC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        0L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 1,
        D_ID,
        W_ID,
        "We",
        "Represent",
        "Customer",
        "Random Department",
        "Place2",
        "BiggerPlace",
        "AL",
        "13908",
        "(913) 909 - 0928",
        new Date(),
        "GC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        1L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 2,
        D_ID,
        W_ID,
        "Who",
        "Is",
        "Customer",
        "Receiving",
        "450 Mass F.X.",
        "BiggerPlace",
        "CI",
        "91083",
        "(541) 931 - 0928",
        new Date(),
        "GC",
        19899324.21,
        .13,
        initialBalance,
        initialYTD,
        2L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 3,
        D_ID,
        W_ID,
        "ICanBe",
        "",
        "Customer",
        "street",
        "place",
        "BiggerPlace",
        "MA",
        "91083",
        "(913) 909 - 0928",
        new Date(),
        "GC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        3L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    // long d_id, long w_id, double h_amount, String c_last, long c_w_id,
    // long c_d_id
    final double paymentAmount = 500.25;

    // VoltTable[] results = client.callProcedure("paymentByCustomerName", W_ID,
    //      D_ID, paymentAmount, W_ID, D_ID, "Customer", new Date());
    // assertEquals(3, results.length);

    // being proc
    voltQueueSQL(getCustomersByLastName, "Customer", D_ID, W_ID);
    final VoltTable customers = voltExecuteSQL()[0];
    final int namecnt = customers.getRowCount();
    if (namecnt == 0) {
      throw new VoltAbortException(
          "no customers with last name: "
              + "Customer"
              + " in warehouse: "
              + W_ID
              + " and in district "
              + D_ID);
    }

    try {
      System.out.println("PAYMENT FOUND CUSTOMERS: " + customers.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final long c_id = customer.getLong(C_ID_IDX);

    voltQueueSQL(getWarehouse, W_ID);
    voltQueueSQL(getDistrict, W_ID, D_ID);
    final VoltTable[] results = voltExecuteSQL();
    final VoltTable warehouse = results[0];
    final VoltTable district = results[1];

    try {
      System.out.println("WAREHOUSE PRE: " + warehouse.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    voltQueueSQL(getWarehouses);
    VoltTable warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE PRE: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    voltQueueSQL(updateWarehouseBalance, paymentAmount, W_ID);
    voltQueueSQL(updateDistrictBalance, paymentAmount, W_ID, D_ID);
    voltExecuteSQL();

    voltQueueSQL(getWarehouses);
    warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE PRE: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    // do stuff to extract district and warehouse info.

    // customer info
    final byte[] c_first = customer.getStringAsBytes(C_FIRST_IDX);
    final byte[] c_middle = customer.getStringAsBytes(C_MIDDLE_IDX);
    final byte[] c_last = customer.getStringAsBytes(C_LAST_IDX);
    final byte[] c_street_1 = customer.getStringAsBytes(C_STREET_1_IDX);
    final byte[] c_street_2 = customer.getStringAsBytes(C_STREET_2_IDX);
    final byte[] c_city = customer.getStringAsBytes(C_CITY_IDX);
    final byte[] c_state = customer.getStringAsBytes(C_STATE_IDX);
    final byte[] c_zip = customer.getStringAsBytes(C_ZIP_IDX);
    final byte[] c_phone = customer.getStringAsBytes(C_PHONE_IDX);
    final TimestampType c_since = customer.getTimestampAsTimestamp(C_SINCE_IDX);
    final byte[] c_credit = customer.getStringAsBytes(C_CREDIT_IDX);
    final double c_credit_lim = customer.getDouble(C_CREDIT_LIM_IDX);
    final double c_discount = customer.getDouble(C_DISCOUNT_IDX);
    final double c_balance = customer.getDouble(C_BALANCE_IDX) - paymentAmount;
    final double c_ytd_payment = customer.getDouble(C_YTD_PAYMENT_IDX) + paymentAmount;
    final long c_payment_cnt = customer.getLong(C_PAYMENT_CNT_IDX) + 1;
    byte[] c_data;
    if (Arrays.equals(c_credit, Constants.BAD_CREDIT_BYTES)) {
      c_data = customer.getStringAsBytes(C_DATA_IDX);
      byte[] newData =
          (c_id + " " + D_ID + " " + W_ID + " " + D_ID + " " + W_ID + " " + paymentAmount + "|")
              .getBytes();

      int newLength = newData.length + c_data.length;
      if (newLength > Constants.MAX_C_DATA) {
        newLength = Constants.MAX_C_DATA;
      }
      ByteBuilder builder = new ByteBuilder(newLength);

      int minLength = newLength;
      if (newData.length < minLength) minLength = newData.length;
      builder.append(newData, 0, minLength);

      int remaining = newLength - minLength;
      builder.append(c_data, 0, remaining);
      c_data = builder.array();
      voltQueueSQL(
          updateBCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_data, W_ID, D_ID, c_id);
    } else {
      c_data = new byte[0];
      voltQueueSQL(updateGCCustomer, c_balance, c_ytd_payment, c_payment_cnt, W_ID, D_ID, c_id);
    }

    // Concatenate w_name, four spaces, d_name
    byte[] w_name = warehouse.fetchRow(0).getStringAsBytes(W_NAME_IDX);
    final byte[] FOUR_SPACES = {' ', ' ', ' ', ' '};
    byte[] d_name = district.fetchRow(0).getStringAsBytes(D_NAME_IDX);
    ByteBuilder builder = new ByteBuilder(w_name.length + FOUR_SPACES.length + d_name.length);
    builder.append(w_name);
    builder.append(FOUR_SPACES);
    builder.append(d_name);
    byte[] h_data = builder.array();

    // Create the history record
    voltQueueSQL(insertHistory, c_id, D_ID, W_ID, D_ID, W_ID, timestamp, paymentAmount, h_data);
    voltExecuteSQL();

    // TPC-C 2.5.3.3: Must display the following fields:
    // W_ID, D_ID, C_ID, C_D_ID, C_W_ID, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP,
    // D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, C_FIRST, C_MIDDLE, C_LAST, C_STREET_1,
    // C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM,
    // C_DISCOUNT, C_BALANCE, the first 200 characters of C_DATA (only if C_CREDIT = "BC"),
    // H_AMOUNT, and H_DATE.

    // Return the entire warehouse and district tuples. The client provided:
    // w_id, d_id, c_d_id, c_w_id, h_amount, h_data.
    // Build a table for the rest
    final VoltTable misc = misc_template.clone(8192);
    misc.addRow(
        c_id,
        c_first,
        c_middle,
        c_last,
        c_street_1,
        c_street_2,
        c_city,
        c_state,
        c_zip,
        c_phone,
        c_since,
        c_credit,
        c_credit_lim,
        c_discount,
        c_balance,
        c_data);

    // Hand back all the warehouse, district, and customer data
    VoltTable[] resultsX = new VoltTable[] {warehouse, district, misc};

    // resume test code

    // check that the middle "Customer" was returned
    assert ((C_ID + 1) == (resultsX[2].fetchRow(0).getLong("c_id")));
    assert ("".equals(resultsX[2].fetchRow(0).getString("c_data")));

    // Verify that both warehouse, district and customer were updated
    // correctly
    // VoltTable[] allTables = client.callProcedure("SelectAll");
    voltQueueSQL(getWarehouses);
    warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE POST: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    assert (1 == warehouses.getRowCount());
    double amt1 = initialYTD + paymentAmount;
    double amt2 = warehouses.fetchRow(0).getDouble("W_YTD");

    assert (amt1 == amt2);

    voltQueueSQL(getDistricts);
    VoltTable districts = voltExecuteSQL()[0];
    assert (1 == districts.getRowCount());
    assert ((initialYTD + paymentAmount) == districts.fetchRow(0).getDouble("D_YTD"));

    voltQueueSQL(getCustomers);
    VoltTable customersX = voltExecuteSQL()[0];
    assert (4 == customersX.getRowCount());
    assert ((C_ID + 1) == customersX.fetchRow(1).getLong("C_ID"));
    assert ((initialBalance - paymentAmount) == customersX.fetchRow(1).getDouble("C_BALANCE"));
    assert ((initialYTD + paymentAmount) == customersX.fetchRow(1).getDouble("C_YTD_PAYMENT"));
    assert (2 == customersX.fetchRow(1).getLong("C_PAYMENT_CNT"));

    return null;
  }
  public void testLoadMultipartitionTable() throws IOException {
    Client client = getClient();
    // make a TPCC warehouse table
    VoltTable partitioned_table =
        new VoltTable(
            new VoltTable.ColumnInfo("W_ID", org.voltdb.VoltType.SMALLINT),
            new VoltTable.ColumnInfo("W_NAME", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_STREET_1", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_STREET_2", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_CITY", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_STATE", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_ZIP", org.voltdb.VoltType.get((byte) 9)),
            new VoltTable.ColumnInfo("W_TAX", org.voltdb.VoltType.get((byte) 8)),
            new VoltTable.ColumnInfo("W_YTD", org.voltdb.VoltType.get((byte) 8)));

    for (int i = 1; i < 21; i++) {
      Object[] row =
          new Object[] {
            new Short((short) i),
            "name_" + i,
            "street1_" + i,
            "street2_" + i,
            "city_" + i,
            "ma",
            "zip_" + i,
            new Double(i),
            new Double(i)
          };
      partitioned_table.addRow(row);
    }

    // make a TPCC item table
    VoltTable replicated_table =
        new VoltTable(
            new VoltTable.ColumnInfo("I_ID", VoltType.INTEGER),
            new VoltTable.ColumnInfo("I_IM_ID", VoltType.INTEGER),
            new VoltTable.ColumnInfo("I_NAME", VoltType.STRING),
            new VoltTable.ColumnInfo("I_PRICE", VoltType.FLOAT),
            new VoltTable.ColumnInfo("I_DATA", VoltType.STRING));

    for (int i = 1; i < 21; i++) {
      Object[] row = new Object[] {i, i, "name_" + i, new Double(i), "data_" + i};

      replicated_table.addRow(row);
    }

    try {
      client.callProcedure("@LoadMultipartitionTable", "WAREHOUSE", partitioned_table);
      client.callProcedure("@LoadMultipartitionTable", "ITEM", replicated_table);
      VoltTable results[] = client.callProcedure("@Statistics", "table", 0).getResults();

      int foundItem = 0;
      // to verify, each of the 2 sites should have 5 warehouses.
      int foundWarehouse = 0;

      System.out.println(results[0]);

      // Check that tables loaded correctly
      while (results[0].advanceRow()) {
        if (results[0].getString("TABLE_NAME").equals("WAREHOUSE")) {
          ++foundWarehouse;
          // Different values depending on local cluster vs. single process hence ||
          assertTrue(
              5 == results[0].getLong("TUPLE_COUNT") || 10 == results[0].getLong("TUPLE_COUNT"));
        }
        if (results[0].getString("TABLE_NAME").equals("ITEM")) {
          ++foundItem;
          // Different values depending on local cluster vs. single process hence ||
          assertTrue(
              10 == results[0].getLong("TUPLE_COUNT") || 20 == results[0].getLong("TUPLE_COUNT"));
        }
      }
      // make sure both warehouses were located
      // Different values depending on local cluster vs. single process hence ||
      assertTrue(2 == foundWarehouse || 4 == foundWarehouse);
      assertTrue(2 == foundItem || 4 == foundItem);
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
  }
  public VoltTable[] processPayment(
      short w_id,
      byte d_id,
      short c_w_id,
      byte c_d_id,
      int c_id,
      double h_amount,
      VoltTableRow customer,
      TimestampType timestamp) {

    // customer info
    final byte[] c_first = customer.getStringAsBytes(C_FIRST_IDX);
    final byte[] c_middle = customer.getStringAsBytes(C_MIDDLE_IDX);
    final byte[] c_last = customer.getStringAsBytes(C_LAST_IDX);
    final byte[] c_street_1 = customer.getStringAsBytes(C_STREET_1_IDX);
    final byte[] c_street_2 = customer.getStringAsBytes(C_STREET_2_IDX);
    final byte[] c_city = customer.getStringAsBytes(C_CITY_IDX);
    final byte[] c_state = customer.getStringAsBytes(C_STATE_IDX);
    final byte[] c_zip = customer.getStringAsBytes(C_ZIP_IDX);
    final byte[] c_phone = customer.getStringAsBytes(C_PHONE_IDX);
    final TimestampType c_since = customer.getTimestampAsTimestamp(C_SINCE_IDX);
    final byte[] c_credit = customer.getStringAsBytes(C_CREDIT_IDX);
    final double c_credit_lim = customer.getDouble(C_CREDIT_LIM_IDX);
    final double c_discount = customer.getDouble(C_DISCOUNT_IDX);
    final double c_balance = customer.getDouble(C_BALANCE_IDX) - h_amount;
    final double c_ytd_payment = customer.getDouble(C_YTD_PAYMENT_IDX) + h_amount;
    final int c_payment_cnt = (int) customer.getLong(C_PAYMENT_CNT_IDX) + 1;
    byte[] c_data;
    if (Arrays.equals(c_credit, Constants.BAD_CREDIT_BYTES)) {
      c_data = customer.getStringAsBytes(C_DATA_IDX);
      byte[] newData =
          (c_id + " " + c_d_id + " " + c_w_id + " " + d_id + " " + w_id + " " + h_amount + "|")
              .getBytes();

      int newLength = newData.length + c_data.length;
      if (newLength > Constants.MAX_C_DATA) {
        newLength = Constants.MAX_C_DATA;
      }
      ByteBuilder builder = new ByteBuilder(newLength);

      int minLength = newLength;
      if (newData.length < minLength) minLength = newData.length;
      builder.append(newData, 0, minLength);

      int remaining = newLength - minLength;
      builder.append(c_data, 0, remaining);
      c_data = builder.array();
      voltQueueSQL(
          updateBCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_data, c_w_id, c_d_id, c_id);
    } else {
      c_data = new byte[0];
      voltQueueSQL(updateGCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_w_id, c_d_id, c_id);
    }
    voltExecuteSQL();

    // TPC-C 2.5.3.3: Must display the following fields:
    // W_ID, D_ID, C_ID, C_D_ID, C_W_ID, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP,
    // D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, C_FIRST, C_MIDDLE, C_LAST, C_STREET_1,
    // C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM,
    // C_DISCOUNT, C_BALANCE, the first 200 characters of C_DATA (only if C_CREDIT = "BC"),
    // H_AMOUNT, and H_DATE.

    // Return the entire warehouse and district tuples. The client provided:
    // w_id, d_id, c_d_id, c_w_id, h_amount, h_data.
    // Build a table for the rest
    final VoltTable misc = misc_template.clone(1024);
    misc.addRow(
        c_id,
        c_first,
        c_middle,
        c_last,
        c_street_1,
        c_street_2,
        c_city,
        c_state,
        c_zip,
        c_phone,
        c_since,
        c_credit,
        c_credit_lim,
        c_discount,
        c_balance,
        c_data);
    return new VoltTable[] {misc};
  }
Beispiel #23
0
  @Override
  public void run() {
    // ratio of upsert for @Load*Table
    final float upsertratio = 0.50F;
    // ratio of upsert to an existing table for @Load*Table
    final float upserthitratio = 0.20F;

    CopyAndDeleteDataTask cdtask = new CopyAndDeleteDataTask();
    cdtask.start();
    try {
      while (m_shouldContinue.get()) {
        // 1 in 3 gets copied and then deleted after leaving some data
        byte shouldCopy = (byte) (m_random.nextInt(3) == 0 ? 1 : 0);
        byte upsertMode = (byte) (m_random.nextFloat() < upsertratio ? 1 : 0);
        byte upsertHitMode =
            (byte) ((upsertMode != 0) && (m_random.nextFloat() < upserthitratio) ? 1 : 0);

        CountDownLatch latch = new CountDownLatch(batchSize);
        final ArrayList<Long> lcpDelQueue = new ArrayList<Long>();

        // try to insert batchSize random rows
        for (int i = 0; i < batchSize; i++) {
          m_table.clearRowData();
          m_permits.acquire();
          long p = Math.abs(r.nextLong());
          m_table.addRow(p, p, Calendar.getInstance().getTimeInMillis());
          boolean success = false;
          if (!m_isMP) {
            Object rpartitionParam =
                TheHashinator.valueToBytes(
                    m_table.fetchRow(0).get(m_partitionedColumnIndex, VoltType.BIGINT));
            if (upsertHitMode
                != 0) { // for test upsert an existing row, insert it and then upsert same row
              // again.
              success =
                  client.callProcedure(
                      new InsertCallback(latch, p, shouldCopy),
                      m_procName,
                      rpartitionParam,
                      m_tableName,
                      (byte) 1,
                      m_table);
            }
            success =
                client.callProcedure(
                    new InsertCallback(latch, p, shouldCopy),
                    m_procName,
                    rpartitionParam,
                    m_tableName,
                    (byte) 1,
                    m_table);
          } else {
            if (upsertHitMode != 0) {
              success =
                  client.callProcedure(
                      new InsertCallback(latch, p, shouldCopy),
                      m_procName,
                      m_tableName,
                      (byte) 1,
                      m_table);
            }
            success =
                client.callProcedure(
                    new InsertCallback(latch, p, shouldCopy),
                    m_procName,
                    m_tableName,
                    (byte) 1,
                    m_table);
          }
          // Ad if successfully queued but remove if proc fails.
          if (success) {
            if (shouldCopy != 0) {
              lcpDelQueue.add(p);
            } else {
              onlyDelQueue.add(p);
            }
          }
        }
        // Wait for all @Load{SP|MP}Done
        latch.await();
        cpDelQueue.addAll(lcpDelQueue);
        long nextRowCount = 0;
        try {
          nextRowCount = TxnId2Utils.getRowCount(client, m_tableName);
        } catch (Exception e) {
          hardStop("getrowcount exception", e);
        }
        // if no progress, throttle a bit
        if (nextRowCount == currentRowCount.get()) {
          Thread.sleep(1000);
        }
        if (onlyDelQueue.size() > 0 && m_shouldContinue.get()) {
          List<Long> workList = new ArrayList<Long>();
          onlyDelQueue.drainTo(workList);
          CountDownLatch odlatch = new CountDownLatch(workList.size());
          for (Long lcid : workList) {
            client.callProcedure(new DeleteCallback(odlatch, 1), m_onlydelprocName, lcid);
          }
          odlatch.await();
        }
      }
      // Any accumulated in p/mp tables are left behind.
    } catch (Exception e) {
      // on exception, log and end the thread, but don't kill the process
      log.error(
          "LoadTableLoader failed a procedure call for table "
              + m_tableName
              + " and the thread will now stop.",
          e);
    } finally {
      cdtask.shutdown();
      try {
        cdtask.join();
      } catch (InterruptedException ex) {
        log.error("CopyDelete Task was stopped.", ex);
      }
    }
  }