private bool BatchSizeExceedsSafeZone(TransactionToApply first, TransactionToApply last) { long lastAppliedTimestamp = last.TransactionRepresentation().TimeCommitted; long firstAppliedTimestamp = first.TransactionRepresentation().TimeCommitted; long chunkLength = lastAppliedTimestamp - firstAppliedTimestamp; return(chunkLength > _idReuseSafeZoneTime); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long append(org.neo4j.kernel.impl.api.TransactionToApply batch, org.neo4j.kernel.impl.transaction.tracing.LogAppendEvent logAppendEvent) throws java.io.IOException public override long Append(TransactionToApply batch, LogAppendEvent logAppendEvent) { // Assigned base tx id just to make compiler happy long lastTransactionId = TransactionIdStore_Fields.BASE_TX_ID; // Synchronized with logFile to get absolute control over concurrent rotations happening lock ( _logFile ) { // Assert that kernel is healthy before making any changes _databaseHealth.assertHealthy(typeof(IOException)); using (SerializeTransactionEvent serialiseEvent = logAppendEvent.BeginSerializeTransaction()) { // Append all transactions in this batch to the log under the same logFile monitor TransactionToApply tx = batch; while (tx != null) { long transactionId = _transactionIdStore.nextCommittingTransactionId(); // If we're in a scenario where we're merely replicating transactions, i.e. transaction // id have already been generated by another entity we simply check that our id // that we generated match that id. If it doesn't we've run into a problem we can't ´ // really recover from and would point to a bug somewhere. MatchAgainstExpectedTransactionIdIfAny(transactionId, tx); TransactionCommitment commitment = AppendToLog(tx.TransactionRepresentation(), transactionId); tx.Commitment(commitment, transactionId); tx.LogPosition(commitment.LogPosition()); tx = tx.Next(); lastTransactionId = transactionId; } } } // At this point we've appended all transactions in this batch, but we can't mark any of them // as committed since they haven't been forced to disk yet. So here we force, or potentially // piggy-back on another force, but anyway after this call below we can be sure that all our transactions // in this batch exist durably on disk. if (ForceAfterAppend(logAppendEvent)) { // We got lucky and were the one forcing the log. It's enough if ones of all doing concurrent committers // checks the need for log rotation. bool logRotated = _logRotation.rotateLogIfNeeded(logAppendEvent); logAppendEvent.LogRotated = logRotated; } // Mark all transactions as committed PublishAsCommitted(batch); return(lastTransactionId); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyIndex(org.neo4j.kernel.impl.api.TransactionToApply tx) throws Exception internal virtual void VerifyIndex(TransactionToApply tx) { using (IndexReader reader = Index.newReader()) { NodeVisitor visitor = new NodeVisitor(); for (int i = 0; tx != null; i++) { tx.TransactionRepresentation().accept(visitor.Clear()); Value propertyValue = propertyValue(Id, Base + i); IndexQuery.ExactPredicate query = IndexQuery.exact(outerInstance.descriptor.PropertyId, propertyValue); LongIterator hits = reader.Query(query); assertEquals("Index doesn't contain " + visitor.NodeId + " " + propertyValue, visitor.NodeId, hits.next()); assertFalse(hits.hasNext()); tx = tx.Next(); } } }
private void MarkUnsafeTransactionsForTermination(TransactionToApply first, TransactionToApply last) { long firstCommittedTimestamp = first.TransactionRepresentation().TimeCommitted; long lastCommittedTimestamp = last.TransactionRepresentation().TimeCommitted; long earliestSafeTimestamp = lastCommittedTimestamp - _idReuseSafeZoneTime; foreach (KernelTransactionHandle txHandle in _kernelTransactions.activeTransactions()) { long commitTimestamp = txHandle.LastTransactionTimestampWhenStarted(); if (commitTimestamp != Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_COMMIT_TIMESTAMP && commitTimestamp < earliestSafeTimestamp) { if (txHandle.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Outdated)) { _log.info("Marking transaction for termination, " + "invalidated due to an upcoming batch of changes being applied:" + "\n" + " Batch: firstCommittedTxId:" + first.TransactionId() + ", firstCommittedTimestamp:" + InformativeTimestamp(firstCommittedTimestamp) + ", lastCommittedTxId:" + last.TransactionId() + ", lastCommittedTimestamp:" + InformativeTimestamp(lastCommittedTimestamp) + ", batchTimeRange:" + InformativeDuration(lastCommittedTimestamp - firstCommittedTimestamp) + ", earliestSafeTimestamp:" + InformativeTimestamp(earliestSafeTimestamp) + ", safeZoneDuration:" + InformativeDuration(_idReuseSafeZoneTime) + "\n" + " Transaction: lastCommittedTimestamp:" + InformativeTimestamp(txHandle.LastTransactionTimestampWhenStarted()) + ", lastCommittedTxId:" + txHandle.LastTransactionIdWhenStarted() + ", localStartTimestamp:" + InformativeTimestamp(txHandle.StartTime())); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long commit(final org.neo4j.kernel.impl.api.TransactionToApply tx, final org.neo4j.kernel.impl.transaction.tracing.CommitEvent commitEvent, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: public override long Commit(TransactionToApply tx, CommitEvent commitEvent, TransactionApplicationMode mode) { TransactionRepresentationReplicatedTransaction transaction = ReplicatedTransaction.from(tx.TransactionRepresentation()); Future <object> futureTxId; try { futureTxId = _replicator.replicate(transaction, true); } catch (ReplicationFailureException e) { throw new TransactionFailureException(ReplicationFailure, e); } try { return(( long )futureTxId.get()); } catch (ExecutionException e) { if (e.InnerException is TransactionFailureException) { throw ( TransactionFailureException )e.InnerException; } // TODO: Panic? throw new Exception(e); } catch (InterruptedException e) { // TODO Wait for the transaction to possibly finish within a user configurable time, before aborting. throw new TransactionFailureException("Interrupted while waiting for txId", e); } }
private void MatchAgainstExpectedTransactionIdIfAny(long transactionId, TransactionToApply tx) { long expectedTransactionId = tx.TransactionId(); if (expectedTransactionId != TRANSACTION_ID_NOT_SPECIFIED) { if (transactionId != expectedTransactionId) { System.InvalidOperationException ex = new System.InvalidOperationException("Received " + tx.TransactionRepresentation() + " with txId:" + expectedTransactionId + " to be applied, but appending it ended up generating an unexpected txId:" + transactionId); _databaseHealth.panic(ex); throw ex; } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long commit(org.neo4j.kernel.impl.api.TransactionToApply batch, org.neo4j.kernel.impl.transaction.tracing.CommitEvent commitEvent, org.neo4j.storageengine.api.TransactionApplicationMode mode) throws org.neo4j.graphdb.TransactionFailureException public override long Commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode) { TransactionsToApply.Add(batch.TransactionRepresentation()); return(-1); }