예제 #1
0
 public static void logFragmentTaskMessage(
     FragmentTaskMessage ftask, long localHSId, long spHandle, boolean borrow) {
   if (iv2log.isTraceEnabled()) {
     String label = "rxFragMsg";
     if (borrow) {
       label = "rxBrrwMsg";
     }
     if (ftask.getSpHandle() != Long.MIN_VALUE && ftask.getSpHandle() != spHandle) {
       iv2log.error(
           "FragmentTaskMessage SP HANDLE conflict.  Message: "
               + ftask.getSpHandle()
               + ", locally held: "
               + spHandle);
     }
     String logmsg = "%s %s from %s txnId %s spHandle %s trunc %s";
     iv2log.trace(
         String.format(
             logmsg,
             label,
             CoreUtils.hsIdToString(localHSId),
             CoreUtils.hsIdToString(ftask.m_sourceHSId),
             txnIdToString(ftask.getTxnId()),
             txnIdToString(spHandle),
             txnIdToString(ftask.getTruncationHandle())));
   }
 }
예제 #2
0
 public static void logIv2InitiateTaskMessage(
     Iv2InitiateTaskMessage itask, long localHSId, long txnid, long spHandle) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "rxInitMsg %s from %s ciHandle %s txnId %s spHandle %s trunc %s";
     if (itask.getTxnId() != Long.MIN_VALUE && itask.getTxnId() != txnid) {
       iv2log.error(
           "Iv2InitiateTaskMessage TXN ID conflict.  Message: "
               + itask.getTxnId()
               + ", locally held: "
               + txnid);
     }
     if (itask.getSpHandle() != Long.MIN_VALUE && itask.getSpHandle() != spHandle) {
       iv2log.error(
           "Iv2InitiateTaskMessage SP HANDLE conflict.  Message: "
               + itask.getSpHandle()
               + ", locally held: "
               + spHandle);
     }
     iv2log.trace(
         String.format(
             logmsg,
             CoreUtils.hsIdToString(localHSId),
             CoreUtils.hsIdToString(itask.m_sourceHSId),
             ClientInterfaceHandleManager.handleToString(itask.getClientInterfaceHandle()),
             txnIdToString(txnid),
             txnIdToString(spHandle),
             txnIdToString(itask.getTruncationHandle())));
   }
 }
예제 #3
0
 public static void logInitiatorRxMsg(VoltMessage msg, long localHSId) {
   if (iv2log.isTraceEnabled()) {
     if (msg instanceof InitiateResponseMessage) {
       InitiateResponseMessage iresp = (InitiateResponseMessage) msg;
       String logmsg = "rxInitRsp %s from %s ciHandle %s txnId %s spHandle %s status %s";
       iv2log.trace(
           String.format(
               logmsg,
               CoreUtils.hsIdToString(localHSId),
               CoreUtils.hsIdToString(iresp.m_sourceHSId),
               ClientInterfaceHandleManager.handleToString(iresp.getClientInterfaceHandle()),
               txnIdToString(iresp.getTxnId()),
               txnIdToString(iresp.getSpHandle()),
               respStatusToString(iresp.getClientResponseData().getStatus())));
     } else if (msg instanceof FragmentResponseMessage) {
       FragmentResponseMessage fresp = (FragmentResponseMessage) msg;
       String logmsg = "rxFragRsp %s from %s txnId %s spHandle %s status %s";
       iv2log.trace(
           String.format(
               logmsg,
               CoreUtils.hsIdToString(localHSId),
               CoreUtils.hsIdToString(fresp.m_sourceHSId),
               txnIdToString(fresp.getTxnId()),
               txnIdToString(fresp.getSpHandle()),
               fragStatusToString(fresp.getStatusCode())));
     }
   }
 }
예제 #4
0
 @Override
 public void logTask(TransactionInfoBaseMessage message) throws IOException {
   assert (!(message instanceof Iv2InitiateTaskMessage));
   if (message instanceof FragmentTaskMessage) {
     if (JOINLOG.isTraceEnabled()) {
       JOINLOG.trace("P" + m_partitionId + " received first fragment");
     }
     m_receivedFirstFragment = true;
   }
   m_taskLog.logTask(message);
 }
예제 #5
0
 public static void logTopology(long leaderHSId, List<Long> replicas, int partitionId) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "topology partition %d leader %s replicas (%s)";
     iv2log.trace(
         String.format(
             logmsg,
             partitionId,
             CoreUtils.hsIdToString(leaderHSId),
             CoreUtils.hsIdCollectionToString(replicas)));
   }
 }
예제 #6
0
 public static void logSiteTaskerQueueOffer(TransactionTask task) {
   if (iv2queuelog.isTraceEnabled()) {
     String logmsg = "tskQOffer txnId %s spHandle %s type %s";
     iv2queuelog.trace(
         String.format(
             logmsg,
             txnIdToString(task.getTxnId()),
             txnIdToString(task.getSpHandle()),
             task.m_txn.isSinglePartition() ? "SP" : "MP"));
   }
 }
예제 #7
0
 /** Process a new repair log response */
 @Override
 public void deliver(VoltMessage message) {
   if (message instanceof Iv2RepairLogResponseMessage) {
     Iv2RepairLogResponseMessage response = (Iv2RepairLogResponseMessage) message;
     if (response.getRequestId() != m_requestId) {
       tmLog.debug(
           m_whoami
               + "rejecting stale repair response."
               + " Current request id is: "
               + m_requestId
               + " Received response for request id: "
               + response.getRequestId());
       return;
     }
     ReplicaRepairStruct rrs = m_replicaRepairStructs.get(response.m_sourceHSId);
     if (rrs.m_expectedResponses < 0) {
       tmLog.debug(
           m_whoami
               + "collecting "
               + response.getOfTotal()
               + " repair log entries from "
               + CoreUtils.hsIdToString(response.m_sourceHSId));
     }
     // Long.MAX_VALUE has rejoin semantics
     if (response.getHandle() != Long.MAX_VALUE) {
       m_maxSeenTxnId = Math.max(m_maxSeenTxnId, response.getHandle());
     }
     if (response.getPayload() != null) {
       m_repairLogUnion.add(response);
       if (tmLog.isTraceEnabled()) {
         tmLog.trace(
             m_whoami
                 + " collected from "
                 + CoreUtils.hsIdToString(response.m_sourceHSId)
                 + ", message: "
                 + response.getPayload());
       }
     }
     if (rrs.update(response)) {
       tmLog.debug(
           m_whoami
               + "collected "
               + rrs.m_receivedResponses
               + " responses for "
               + rrs.m_expectedResponses
               + " repair log entries from "
               + CoreUtils.hsIdToString(response.m_sourceHSId));
       if (areRepairLogsComplete()) {
         repairSurvivors();
       }
     }
   }
 }
예제 #8
0
 public static void logFinishTransaction(InitiateResponseMessage msg, long localHSId) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "finishTxn %s ciHandle %s initHSId %s status %s";
     iv2log.trace(
         String.format(
             logmsg,
             CoreUtils.hsIdToString(localHSId),
             ClientInterfaceHandleManager.handleToString(msg.getClientInterfaceHandle()),
             CoreUtils.hsIdToString(msg.getCoordinatorHSId()),
             respStatusToString(msg.getClientResponseData().getStatus())));
   }
 }
예제 #9
0
 public static void logCreateTransaction(Iv2InitiateTaskMessage msg) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "createTxn %s ciHandle %s initHSId %s proc %s";
     iv2log.trace(
         String.format(
             logmsg,
             CoreUtils.hsIdToString(msg.getInitiatorHSId()),
             ClientInterfaceHandleManager.handleToString(msg.getClientInterfaceHandle()),
             CoreUtils.hsIdToString(msg.getCoordinatorHSId()),
             msg.getStoredProcedureInvocation().getProcName()));
   }
 }
예제 #10
0
 public static void logIv2MultipartSentinel(
     MultiPartitionParticipantMessage message, long localHSId, long txnId) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "rxSntlMsg %s from %s txnId %s";
     iv2log.trace(
         String.format(
             logmsg,
             CoreUtils.hsIdToString(localHSId),
             CoreUtils.hsIdToString(message.m_sourceHSId),
             txnIdToString(txnId)));
   }
 }
예제 #11
0
 public static void logCompleteTransactionMessage(
     CompleteTransactionMessage ctask, long localHSId) {
   if (iv2log.isTraceEnabled()) {
     String logmsg = "rxCompMsg %s from %s txnId %s %s %s";
     iv2log.trace(
         String.format(
             logmsg,
             CoreUtils.hsIdToString(localHSId),
             CoreUtils.hsIdToString(ctask.m_sourceHSId),
             txnIdToString(ctask.getTxnId()),
             ctask.isRollback() ? "ROLLBACK" : "COMMIT",
             ctask.isRestart() ? "RESTART" : ""));
   }
 }
예제 #12
0
  /** Send missed-messages to survivors. */
  public void repairSurvivors() {
    // cancel() and repair() must be synchronized by the caller (the deliver lock,
    // currently). If cancelled and the last repair message arrives, don't send
    // out corrections!
    if (this.m_promotionResult.isCancelled()) {
      tmLog.debug(m_whoami + "Skipping repair message creation for cancelled Term.");
      return;
    }

    int queued = 0;
    tmLog.debug(m_whoami + "received all repair logs and is repairing surviving replicas.");
    for (Iv2RepairLogResponseMessage li : m_repairLogUnion) {
      List<Long> needsRepair = new ArrayList<Long>(5);
      for (Entry<Long, ReplicaRepairStruct> entry : m_replicaRepairStructs.entrySet()) {
        if (entry.getValue().needs(li.getHandle())) {
          ++queued;
          tmLog.debug(
              m_whoami
                  + "repairing "
                  + CoreUtils.hsIdToString(entry.getKey())
                  + ". Max seen "
                  + entry.getValue().m_maxSpHandleSeen
                  + ". Repairing with "
                  + li.getHandle());
          needsRepair.add(entry.getKey());
        }
      }
      if (!needsRepair.isEmpty()) {
        if (tmLog.isTraceEnabled()) {
          tmLog.trace(
              m_whoami
                  + "repairing: "
                  + CoreUtils.hsIdCollectionToString(needsRepair)
                  + " with message: "
                  + li.getPayload());
        }
        m_mailbox.repairReplicasWith(needsRepair, li.getPayload());
      }
    }
    tmLog.debug(m_whoami + "finished queuing " + queued + " replica repair messages.");

    m_promotionResult.done(m_maxSeenTxnId);
  }
예제 #13
0
 /**
  * Log and exit if a dependency list fails an invariant.
  *
  * @param dependencyId
  * @param dependencies
  */
 void verifyDependencySanity(final Integer dependencyId, final List<VoltTable> dependencies) {
   if (dependencies == null) {
     hostLog.l7dlog(
         Level.FATAL,
         LogKeys.host_ExecutionSite_DependencyNotFound.name(),
         new Object[] {dependencyId},
         null);
     VoltDB.crashLocalVoltDB("No additional info.", false, null);
     // Prevent warnings.
     return;
   }
   for (final Object dependency : dependencies) {
     if (dependency == null) {
       hostLog.l7dlog(
           Level.FATAL,
           LogKeys.host_ExecutionSite_DependencyContainedNull.name(),
           new Object[] {dependencyId},
           null);
       VoltDB.crashLocalVoltDB("No additional info.", false, null);
       // Prevent warnings.
       return;
     }
     if (log.isTraceEnabled()) {
       log.l7dlog(
           Level.TRACE,
           LogKeys.org_voltdb_ExecutionSite_ImportingDependency.name(),
           new Object[] {dependencyId, dependency.getClass().getName(), dependency.toString()},
           null);
     }
     if (!(dependency instanceof VoltTable)) {
       hostLog.l7dlog(
           Level.FATAL,
           LogKeys.host_ExecutionSite_DependencyNotVoltTable.name(),
           new Object[] {dependencyId},
           null);
       VoltDB.crashLocalVoltDB("No additional info.", false, null);
     }
   }
 }
예제 #14
0
  public ClientResponseImpl call(Object... paramListIn) {
    // verify per-txn state has been reset
    assert (m_statusCode == ClientResponse.UNINITIALIZED_APP_STATUS_CODE);
    assert (m_statusString == null);
    assert (m_cachedRNG == null);

    // reset the hash of results
    m_inputCRC.reset();

    // use local var to avoid warnings about reassigning method argument
    Object[] paramList = paramListIn;

    ClientResponseImpl retval = null;
    // assert no sql is queued
    assert (m_batch.size() == 0);

    try {
      m_statsCollector.beginProcedure();

      byte status = ClientResponse.SUCCESS;
      VoltTable[] results = null;

      // inject sysproc execution context as the first parameter.
      if (isSystemProcedure()) {
        final Object[] combinedParams = new Object[paramList.length + 1];
        combinedParams[0] = m_systemProcedureContext;
        for (int i = 0; i < paramList.length; ++i) combinedParams[i + 1] = paramList[i];
        // swap the lists.
        paramList = combinedParams;
      }

      if (paramList.length != m_paramTypes.length) {
        m_statsCollector.endProcedure(false, true, null, null);
        String msg =
            "PROCEDURE "
                + m_procedureName
                + " EXPECTS "
                + String.valueOf(m_paramTypes.length)
                + " PARAMS, BUT RECEIVED "
                + String.valueOf(paramList.length);
        status = ClientResponse.GRACEFUL_FAILURE;
        return getErrorResponse(status, msg, null);
      }

      for (int i = 0; i < m_paramTypes.length; i++) {
        try {
          paramList[i] =
              ParameterConverter.tryToMakeCompatible(
                  m_paramTypeIsPrimitive[i],
                  m_paramTypeIsArray[i],
                  m_paramTypes[i],
                  m_paramTypeComponentType[i],
                  paramList[i]);
        } catch (Exception e) {
          m_statsCollector.endProcedure(false, true, null, null);
          String msg =
              "PROCEDURE "
                  + m_procedureName
                  + " TYPE ERROR FOR PARAMETER "
                  + i
                  + ": "
                  + e.toString();
          status = ClientResponse.GRACEFUL_FAILURE;
          return getErrorResponse(status, msg, null);
        }
      }

      boolean error = false;
      boolean abort = false;
      // run a regular java class
      if (m_catProc.getHasjava()) {
        try {
          if (log.isTraceEnabled()) {
            log.trace(
                "invoking... procMethod="
                    + m_procMethod.getName()
                    + ", class="
                    + getClass().getName());
          }
          try {
            Object rawResult = m_procMethod.invoke(m_procedure, paramList);
            results = getResultsFromRawResults(rawResult);
          } catch (IllegalAccessException e) {
            // If reflection fails, invoke the same error handling that other exceptions do
            throw new InvocationTargetException(e);
          }
          log.trace("invoked");
        } catch (InvocationTargetException itex) {
          // itex.printStackTrace();
          Throwable ex = itex.getCause();
          if (ex instanceof VoltAbortException && !(ex instanceof EEException)) {
            abort = true;
          } else {
            error = true;
          }
          if (ex instanceof Error) {
            m_statsCollector.endProcedure(false, true, null, null);
            throw (Error) ex;
          }

          retval = getErrorResponse(ex);
        }
      }
      // single statement only work
      // (this could be made faster, but with less code re-use)
      else {
        assert (m_catProc.getStatements().size() == 1);
        try {
          m_cachedSingleStmt.params = getCleanParams(m_cachedSingleStmt.stmt, paramList);
          if (getHsqlBackendIfExists() != null) {
            // HSQL handling
            CatalogMap<StmtParameter> sparamsMap = m_cachedSingleStmt.stmt.catStmt.getParameters();
            List<StmtParameter> sparams = CatalogUtil.getSortedCatalogItems(sparamsMap, "index");
            VoltTable table =
                getHsqlBackendIfExists()
                    .runSQLWithSubstitutions(
                        m_cachedSingleStmt.stmt, m_cachedSingleStmt.params, sparams);
            results = new VoltTable[] {table};
          } else {
            m_batch.add(m_cachedSingleStmt);
            results = voltExecuteSQL(true);
          }
        } catch (SerializableException ex) {
          retval = getErrorResponse(ex);
        }
      }

      // Record statistics for procedure call.
      StoredProcedureInvocation invoc = (m_txnState != null ? m_txnState.getInvocation() : null);
      ParameterSet paramSet = (invoc != null ? invoc.getParams() : null);
      m_statsCollector.endProcedure(abort, error, results, paramSet);

      // don't leave empty handed
      if (results == null) results = new VoltTable[0];

      if (retval == null)
        retval = new ClientResponseImpl(status, m_statusCode, m_statusString, results, null);

      int hash = (int) m_inputCRC.getValue();
      if ((retval.getStatus() == ClientResponse.SUCCESS) && (hash != 0)) {
        retval.setHash(hash);
      }
      if ((m_txnState != null)
          && // may be null for tests
          (m_txnState.getInvocation() != null)
          && (m_txnState.getInvocation().getType() == ProcedureInvocationType.REPLICATED)) {
        retval.convertResultsToHashForDeterminism();
      }
    } finally {
      // finally at the call(..) scope to ensure params can be
      // garbage collected and that the queue will be empty for
      // the next call
      m_batch.clear();

      // reset other per-txn state
      m_txnState = null;
      m_statusCode = ClientResponse.UNINITIALIZED_APP_STATUS_CODE;
      m_statusString = null;
      m_cachedRNG = null;
      m_cachedSingleStmt.params = null;
      m_cachedSingleStmt.expectation = null;
      m_seenFinalBatch = false;
    }

    return retval;
  }
예제 #15
0
  /**
   * Process a message pulled off from the network thread, and discard the container once it's
   * processed.
   *
   * @param msg A pair of <sourceHSId, blockContainer>
   * @return The restore work, or null if there's no data block to return to the site.
   */
  private RestoreWork processMessage(
      Pair<Long, Pair<Long, BBContainer>> msg, CachedByteBufferAllocator resultBufferAllocator) {
    if (msg == null) {
      return null;
    }

    RestoreWork restoreWork = null;
    long hsId = msg.getFirst();
    long targetId = msg.getSecond().getFirst();
    BBContainer container = msg.getSecond().getSecond();
    try {
      ByteBuffer block = container.b();
      byte typeByte = block.get(StreamSnapshotDataTarget.typeOffset);
      final int blockIndex = block.getInt(StreamSnapshotDataTarget.blockIndexOffset);
      StreamSnapshotMessageType type = StreamSnapshotMessageType.values()[typeByte];
      if (type == StreamSnapshotMessageType.FAILURE) {
        VoltDB.crashLocalVoltDB("Rejoin source sent failure message.", false, null);

        // for test code only
        if (m_expectedEOFs.decrementAndGet() == 0) {
          m_EOF = true;
        }
      } else if (type == StreamSnapshotMessageType.END) {
        if (rejoinLog.isTraceEnabled()) {
          rejoinLog.trace("Got END message " + blockIndex);
        }

        // End of stream, no need to ack this buffer
        if (m_expectedEOFs.decrementAndGet() == 0) {
          m_EOF = true;
        }
      } else if (type == StreamSnapshotMessageType.SCHEMA) {
        rejoinLog.trace("Got SCHEMA message");

        block.position(StreamSnapshotDataTarget.contentOffset);
        byte[] schemaBytes = new byte[block.remaining()];
        block.get(schemaBytes);
        m_schemas.put(block.getInt(StreamSnapshotDataTarget.tableIdOffset), schemaBytes);
      } else if (type == StreamSnapshotMessageType.HASHINATOR) {
        block.position(StreamSnapshotDataTarget.contentOffset);
        long version = block.getLong();
        byte[] hashinatorConfig = new byte[block.remaining()];
        block.get(hashinatorConfig);

        restoreWork = new HashinatorRestoreWork(version, hashinatorConfig);
      } else {
        // It's normal snapshot data afterwards

        final int tableId = block.getInt(StreamSnapshotDataTarget.tableIdOffset);

        if (!m_schemas.containsKey(tableId)) {
          VoltDB.crashLocalVoltDB("No schema for table with ID " + tableId, false, null);
        }

        // Get the byte buffer ready to be consumed
        block.position(StreamSnapshotDataTarget.contentOffset);
        ByteBuffer nextChunk = getNextChunk(m_schemas.get(tableId), block, resultBufferAllocator);
        m_bytesReceived += nextChunk.remaining();

        restoreWork = new TableRestoreWork(tableId, nextChunk);
      }

      // Queue ack to this block
      m_ack.ack(hsId, m_EOF, targetId, blockIndex);

      return restoreWork;
    } finally {
      container.discard();
    }
  }