Load the specified list of edit files into the image.
@return the txid of the current transaction (next to be loaded
482550
protected long loadEdits(Iterable<EditLogInputStream> editStreams) 
      throws IOException {

    long lastAppliedTxId = storage.getMostRecentCheckpointTxId();
    int numLoaded = 0;
    FSEditLogLoader loader = new FSEditLogLoader(namesystem);
      
    // Load latest edits
    for (EditLogInputStream editIn : editStreams) {
      FLOG.info("Load Image: Reading edits: " + editIn + " last applied txid#: "
          + lastAppliedTxId);
      numLoaded += loader.loadFSEdits(editIn, lastAppliedTxId);  
      lastAppliedTxId = loader.getLastAppliedTxId();
    }
    editLog.setLastWrittenTxId(lastAppliedTxId);
    FLOG.info("Load Image: Number of edit transactions loaded: "
        + numLoaded + " last applied txid: " + lastAppliedTxId);

    // update the counts
    namesystem.dir.updateCountForINodeWithQuota();    
    return numLoaded;
  }
698182
def get_subdomain_ops_at_txid(self, txid, cur=None):
        
        get_cmd = 'SELECT * FROM {} WHERE txid = ? ORDER BY zonefile_offset'.format(self.subdomain_table)

        cursor = None
        if cur is None:
            cursor = self.conn.cursor()
        else:
            cursor = cur

        db_query_execute(cursor, get_cmd, (txid,))

        try:
            return [x for x in cursor.fetchall()]
        except Exception as e:
            if BLOCKSTACK_DEBUG:
                log.exception(e)

            return []
393464
public static EditLogInputStream getInputStream(JournalManager jm, long txid)
      throws IOException {
    List<EditLogInputStream> streams = new ArrayList<EditLogInputStream>();
    jm.selectInputStreams(streams, txid, true, false);
    if (streams.size() < 1) {
      throw new IOException("Cannot obtain stream for txid: " + txid);
    }
    Collections.sort(streams, JournalSet.EDIT_LOG_INPUT_STREAM_COMPARATOR);
    
    // we want the "oldest" available stream
    if (txid == HdfsConstants.INVALID_TXID) {
      return streams.get(0);
    }
    
    // we want a specific stream
    for (EditLogInputStream elis : streams) {
      if (elis.getFirstTxId() == txid) {
        return elis;
      }
    }
    // we cannot obtain the stream
    throw new IOException("Cannot obtain stream for txid: " + txid);
  }
1129761
@Override
    protected void load() {
        //recordId can be null when in batchMode
        if (this.recordId != null && this.properties.isEmpty()) {
            this.sqlgGraph.tx().readWrite();
            if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().getBatchManager().isStreaming()) {
                throw new IllegalStateException("streaming is in progress, first flush or commit before querying.");
            }

            //Generate the columns to prevent 'ERROR: cached plan must not change result type" error'
            //This happens when the schema changes after the statement is prepared.
            @SuppressWarnings("OptionalGetWithoutIsPresent")
            EdgeLabel edgeLabel = this.sqlgGraph.getTopology().getSchema(this.schema).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", this.schema))).getEdgeLabel(this.table).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel %s not found", this.table)));
            StringBuilder sql = new StringBuilder("SELECT\n\t");
            sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID"));
            appendProperties(edgeLabel, sql);
            List<VertexLabel> outForeignKeys = new ArrayList<>();
            for (VertexLabel vertexLabel : edgeLabel.getOutVertexLabels()) {
                outForeignKeys.add(vertexLabel);
                sql.append(", ");
                if (vertexLabel.hasIDPrimaryKey()) {
                    String foreignKey = vertexLabel.getSchema().getName() + "." + vertexLabel.getName() + Topology.OUT_VERTEX_COLUMN_END;
                    sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(foreignKey));
                } else {
                    int countIdentifier = 1;
                    for (String identifier : vertexLabel.getIdentifiers()) {
                        PropertyColumn propertyColumn = vertexLabel.getProperty(identifier).orElseThrow(
                                () -> new IllegalStateException(String.format("identifier %s column must be a property", identifier))
                        );
                        PropertyType propertyType = propertyColumn.getPropertyType();
                        String[] propertyTypeToSqlDefinition = this.sqlgGraph.getSqlDialect().propertyTypeToSqlDefinition(propertyType);
                        int count = 1;
                        for (String ignored : propertyTypeToSqlDefinition) {
                            if (count > 1) {
                                sql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(vertexLabel.getFullName() + "." + identifier + propertyType.getPostFixes()[count - 2] + Topology.OUT_VERTEX_COLUMN_END));
                            } else {
                                //The first column existVertexLabel no postfix
                                sql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(vertexLabel.getFullName() + "." + identifier + Topology.OUT_VERTEX_COLUMN_END));
                            }
                            if (count++ < propertyTypeToSqlDefinition.length) {
                                sql.append(", ");
                            }
                        }
                        if (countIdentifier++ < vertexLabel.getIdentifiers().size()) {
                            sql.append(", ");
                        }
                    }
                }
            }
            List<VertexLabel> inForeignKeys = new ArrayList<>();
            for (VertexLabel vertexLabel : edgeLabel.getInVertexLabels()) {
                sql.append(", ");
                inForeignKeys.add(vertexLabel);
                if (vertexLabel.hasIDPrimaryKey()) {
                    String foreignKey = vertexLabel.getSchema().getName() + "." + vertexLabel.getName() + Topology.IN_VERTEX_COLUMN_END;
                    sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(foreignKey));
                } else {
                    int countIdentifier = 1;
                    for (String identifier : vertexLabel.getIdentifiers()) {
                        PropertyColumn propertyColumn = vertexLabel.getProperty(identifier).orElseThrow(
                                () -> new IllegalStateException(String.format("identifier %s column must be a property", identifier))
                        );
                        PropertyType propertyType = propertyColumn.getPropertyType();
                        String[] propertyTypeToSqlDefinition = this.sqlgGraph.getSqlDialect().propertyTypeToSqlDefinition(propertyType);
                        int count = 1;
                        for (String ignored : propertyTypeToSqlDefinition) {
                            if (count > 1) {
                                sql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(vertexLabel.getFullName() + "." + identifier + propertyType.getPostFixes()[count - 2] + Topology.IN_VERTEX_COLUMN_END));
                            } else {
                                //The first column existVertexLabel no postfix
                                sql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(vertexLabel.getFullName() + "." + identifier + Topology.IN_VERTEX_COLUMN_END));
                            }
                            if (count++ < propertyTypeToSqlDefinition.length) {
                                sql.append(", ");
                            }
                        }
                        if (countIdentifier++ < vertexLabel.getIdentifiers().size()) {
                            sql.append(", ");
                        }
                    }
                }
            }
            sql.append("\nFROM\n\t");
            sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema));
            sql.append(".");
            sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(EDGE_PREFIX + this.table));
            sql.append(" WHERE ");
            //noinspection Duplicates
            if (edgeLabel.hasIDPrimaryKey()) {
                sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID"));
                sql.append(" = ?");
            } else {
                int count = 1;
                for (String identifier : edgeLabel.getIdentifiers()) {
                    sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(identifier));
                    sql.append(" = ?");
                    if (count++ < edgeLabel.getIdentifiers().size()) {
                        sql.append(" AND ");
                    }

                }
            }
            if (this.sqlgGraph.getSqlDialect().needsSemicolon()) {
                sql.append(";");
            }
            Connection conn = this.sqlgGraph.tx().getConnection();
            if (logger.isDebugEnabled()) {
                logger.debug(sql.toString());
            }
            try (PreparedStatement preparedStatement = conn.prepareStatement(sql.toString())) {
                if (edgeLabel.hasIDPrimaryKey()) {
                    preparedStatement.setLong(1, this.recordId.sequenceId());
                } else {
                    int count = 1;
                    for (Comparable identifierValue : this.recordId.getIdentifiers()) {
                        preparedStatement.setObject(count++, identifierValue);
                    }
                }
                ResultSet resultSet = preparedStatement.executeQuery();
                if (resultSet.next()) {
                    loadResultSet(resultSet, inForeignKeys, outForeignKeys);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
1194446
protected function getNextId() {
    try {
      $sequenceMapper = $this->getSequenceMapper();
      $sequenceTable = $sequenceMapper->getRealTableName();
      $sequenceConn = $sequenceMapper->getConnection();
      $tableName = strtolower($this->getRealTableName());

      // run id sequence in it's own transaction, if supported
      if (!$this->isFileDB) {
        $sequenceConn->beginTransaction();
      }
      if ($this->idSelectStmt == null) {
        $this->idSelectStmt = $sequenceConn->prepare("SELECT ".$this->quoteIdentifier("id").
                " FROM ".$this->quoteIdentifier($sequenceTable)." WHERE ".
                $this->quoteIdentifier("table")."=".$this->quoteValue($tableName));
      }
      if ($this->idInsertStmt == null) {
        $this->idInsertStmt = $sequenceConn->prepare("INSERT INTO ".
                $this->quoteIdentifier($sequenceTable)." (".$this->quoteIdentifier("id").
                ", ".$this->quoteIdentifier("table").") VALUES (1, ".
                $this->quoteValue($tableName).")");
      }
      if ($this->idUpdateStmt == null) {
        $this->idUpdateStmt = $sequenceConn->prepare("UPDATE ".$this->quoteIdentifier($sequenceTable).
                " SET ".$this->quoteIdentifier("id")."=(".$this->quoteIdentifier("id")."+1) WHERE ".
                $this->quoteIdentifier("table")."=".$this->quoteValue($tableName));
      }
      $this->idSelectStmt->execute();
      $rows = $this->idSelectStmt->fetchAll(PDO::FETCH_ASSOC);
      if (sizeof($rows) == 0) {
        $this->idInsertStmt->execute();
        $this->idInsertStmt->closeCursor();
        $rows = [['id' => 1]];
      }
      $id = $rows[0]['id'];
      $this->idUpdateStmt->execute();
      $this->idUpdateStmt->closeCursor();
      $this->idSelectStmt->closeCursor();
      if (!$this->isFileDB) {
        $sequenceConn->commit();
      }
      return $id;
    }
    catch (\Exception $ex) {
      self::$logger->error("The next id query caused the following exception:\n".$ex->getMessage());
      throw new PersistenceException("Error in persistent operation. See log file for details.");
    }
  }
499142
public static ImmutableList<File> loadFileList(final File fileList) throws IOException {
    return loadFileList(Files.asCharSource(fileList, Charsets.UTF_8));
  }
728113
private void openInputStream(File txFile) throws IOException {
    int ioExceptionRetryCount = 0, logHeaderCorruptRetryCount = 0;
    
    LOG.info("Trying to load the edit log from " + txFile.getAbsolutePath());
    
    do {
      try {
        inputStream = new EditLogFileInputStream(txFile);
        editLogFilePosition = inputStream.getPosition();
        curStreamConsumed = false;
        curStreamFinished = false;
        readNullAfterStreamFinished = false;
        LOG.info("Successfully loaded the edits log from " +
            txFile.getAbsolutePath());
        break;
        
      } catch (LogHeaderCorruptException e1) {
        if (logHeaderCorruptRetryCount == LOG_HEADER_CORRUPT_RETRY_MAX) {
          LOG.error("Failed to load the edit log. No retries left.", e1);
          throw new IOException("Could not load the edit log");
        }
        logHeaderCorruptRetryCount ++;
        LOG.warn("Failed to load the edit log. Retry " +
            logHeaderCorruptRetryCount + " ...", e1);
        try {
          Thread.sleep(ioExceptionRetryCount * LOG_HEADER_CORRUPT_BASE_SLEEP);
        } catch (InterruptedException e) {
          throw new IOException(e);
        }
        
      } catch (IOException e2) {
        if (ioExceptionRetryCount == IO_EXCEPTION_RETRY_MAX) {
          LOG.error("Failed to load the edit log. No retries left.", e2);
          throw new IOException("Could not load the edit log");
        }
        ioExceptionRetryCount ++;
        LOG.warn("Failed to load the edit log. Retry " +
            ioExceptionRetryCount + " ...", e2);
        try {
          Thread.sleep(ioExceptionRetryCount * IO_EXCEPTION_BASE_SLEEP);
        } catch (InterruptedException e) {
          throw new IOException(e);
        }
      }
      
    } while (true);
  }
869405
private boolean shouldLoad(long txid) {
    boolean shouldLoad = txid > standby.getLastCorrectTxId();
    if (!shouldLoad) {
      LOG.info("Ingest: skip loading txId: " + txid
          + " to namesystem, but writing to edit log, last correct txid: " 
          + standby.getLastCorrectTxId());
    }
    return shouldLoad;
  }
1054569
@Override
    public CompletableFuture<Void> completeCommittingTransactions(VersionedMetadata<CommittingTransactionsRecord> record) {
        // create all transaction entries in committing txn list. 
        // remove all entries from active txn in epoch. 
        // reset CommittingTxnRecord
        long time = System.currentTimeMillis();

        Map<String, byte[]> completedRecords = record.getObject().getTransactionsToCommit().stream()
                                                               .collect(Collectors.toMap(UUID::toString, 
                                                                       x -> new CompletedTxnRecord(time, TxnStatus.COMMITTED).toBytes()));
        CompletableFuture<Void> future;
        if (record.getObject().getTransactionsToCommit().size() == 0) {
            future = CompletableFuture.completedFuture(null);
        } else {
            future = createCompletedTxEntries(completedRecords)
                    .thenCompose(x -> getTransactionsInEpochTable(record.getObject().getEpoch())
                            .thenCompose(table -> storeHelper.removeEntries(table, completedRecords.keySet())))
                    .thenCompose(x -> tryRemoveOlderTransactionsInEpochTables(epoch -> epoch < record.getObject().getEpoch()));
        }
        return future
                .thenCompose(x -> Futures.toVoid(updateCommittingTxnRecord(new VersionedMetadata<>(CommittingTransactionsRecord.EMPTY,
                        record.getVersion()))));
    }
659791
public String getTransactionId()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "getTransactionId");
    
    String tranID = null;
    PersistentTranId pTranID = itemStream.getTransactionId();
    
    if (pTranID != null)
    {
      tranID = pTranID.toTMString(); 
    }
      
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "getTransactionId", tranID);
    return tranID;
  }
689573
def get_block_containing_tx(self, txid):
        
        blocks = list(backend.query.get_block_with_transaction(self.connection, txid))
        if len(blocks) > 1:
            logger.critical('Transaction id %s exists in multiple blocks', txid)

        return [block['height'] for block in blocks]
1223246
private Long getTransactorID() {
    if (tnode == null) {
      tnode = env.getSharedResources().getTransactorNode();
    }
    return tnode.getTransactorID().getLongID();
  }
90183
synchronized public int getTransactionID() {
        /*
         * Ensure that the transaction ID is in the valid range between
         * 0 and MAX_TRANSACTION_ID (65534).  If not, the value will be forced
         * to 0.
         */
        if (transactionID < Modbus.DEFAULT_TRANSACTION_ID && isCheckingValidity()) {
            transactionID = Modbus.DEFAULT_TRANSACTION_ID;
        }
        if (transactionID >= Modbus.MAX_TRANSACTION_ID) {
            transactionID = Modbus.DEFAULT_TRANSACTION_ID;
        }
        return transactionID;
    }
93811
public static TransactionException transactionOpen(TransactionOLTP tx) {
        return create(ErrorMessage.TRANSACTION_ALREADY_OPEN.getMessage(tx.keyspace()));
    }
1044557
def load_transactions(input_file, **kwargs):
    
    delimiter = kwargs.get('delimiter', '\t')
    for transaction in csv.reader(input_file, delimiter=delimiter):
        yield transaction if transaction else ['']
125380
public Index open(Transaction tx) {
		TableInfo ti = VanillaDb.catalogMgr().getTableInfo(tblName, tx);
		if (ti == null)
			throw new TableNotFoundException("table '" + tblName
					+ "' is not defined in catalog.");

		return Index.newInstance(this, new SearchKeyType(ti.schema(), fldNames), tx);
	}
307466
private SITransaction getCurrentTransaction() {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "getCurrentTransaction");
        }

        SITransaction currentTransaction = null;

        // Is there a current local transaction?

        if (_localTransaction != null) {

            currentTransaction = _localTransaction.getCurrentTransaction();

        }

        // If not, is there a current global transaction?

        if ((currentTransaction == null) && (_xaResource != null)) {

            currentTransaction = _xaResource.getCurrentTransaction();

        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr
                    .exit(this, TRACE, "getCurrentTransaction",
                            currentTransaction);
        }
        return currentTransaction;

    }