Exemplo n.º 1
0
 /**
  * Set the Exception that is causing this txn to abort. It will need to be processed later on.
  * This is a thread-safe operation. Only the first error will be stored.
  *
  * @param error
  */
 public synchronized void setPendingError(SerializableException error) {
   assert (error != null) : "Trying to set a null error for txn #" + this.txn_id;
   if (this.pending_error == null) {
     if (debug.val)
       LOG.warn(
           String.format(
               "%s - Got %s error for txn: %s",
               this, error.getClass().getSimpleName(), error.getMessage()));
     this.pending_error = error;
   }
 }
  @Override
  protected void flattenToBuffer(final DBBPool pool) throws IOException {
    int msgsize = 4 + 4 + 8 + 1 + 1 + 1 + 2;
    assert (m_exception == null || m_status != SUCCESS);

    if (m_exception != null) {
      msgsize += m_exception.getSerializedSize();
    } else {
      msgsize += 4; // Still serialize exception length 0
    }

    // stupid lame flattening of the tables
    ByteBuffer tableBytes = null;
    if (m_dependencyCount > 0) {

      FastSerializer fs = new FastSerializer();
      try {
        for (int i = 0; i < m_dependencyCount; i++) fs.writeObject(m_dependencies.get(i));
      } catch (IOException e) {
        e.printStackTrace();
        assert (false);
      }
      tableBytes = fs.getBuffer();
      msgsize += tableBytes.remaining();
      msgsize += 4 * m_dependencyCount;
    }

    if (m_buffer == null) {
      m_container = pool.acquire(msgsize + 1 + HEADER_SIZE);
      m_buffer = m_container.b;
    }
    setBufferSize(msgsize + 1, pool);

    m_buffer.position(HEADER_SIZE);
    m_buffer.put(FRAGMENT_RESPONSE_ID);

    m_buffer.putInt(m_executorSiteId);
    m_buffer.putInt(m_destinationSiteId);
    m_buffer.putLong(m_txnId);
    m_buffer.put(m_status);
    m_buffer.put((byte) (m_dirty ? 1 : 0));
    m_buffer.put((byte) (m_recovering ? 1 : 0));
    m_buffer.putShort(m_dependencyCount);
    for (int i = 0; i < m_dependencyCount; i++) m_buffer.putInt(m_dependencyIds.get(i));
    if (tableBytes != null) m_buffer.put(tableBytes);
    if (m_exception != null) {
      m_exception.serializeToBuffer(m_buffer);
    } else {
      m_buffer.putInt(0);
    }

    m_buffer.limit(m_buffer.position());
  }
 @Override
 protected void initFromBuffer() {
   m_buffer.position(HEADER_SIZE + 1); // skip the msg id
   m_executorSiteId = m_buffer.getInt();
   m_destinationSiteId = m_buffer.getInt();
   m_txnId = m_buffer.getLong();
   m_status = m_buffer.get();
   m_dirty = m_buffer.get() == 0 ? false : true;
   m_recovering = m_buffer.get() == 0 ? false : true;
   m_dependencyCount = m_buffer.getShort();
   // assert(m_dependencyCount <= 50);
   for (int i = 0; i < m_dependencyCount; i++) m_dependencyIds.add(m_buffer.getInt());
   for (int i = 0; i < m_dependencyCount; i++) {
     FastDeserializer fds = new FastDeserializer(m_buffer);
     try {
       m_dependencies.add(fds.readObject(VoltTable.class));
     } catch (IOException e) {
       e.printStackTrace();
       assert (false);
     }
   }
   m_exception = SerializableException.deserializeFromBuffer(m_buffer);
 }