use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method verifyTransaction.
private static void verifyTransaction(TransactionMetadataCache positionCache, byte[] additionalHeader, long timeStarted, long latestCommittedTxWhenStarted, long timeCommitted, LogicalTransactionStore store) throws IOException {
try (TransactionCursor cursor = store.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
boolean hasNext = cursor.next();
assertTrue(hasNext);
CommittedTransactionRepresentation tx = cursor.get();
TransactionRepresentation transaction = tx.getTransactionRepresentation();
assertArrayEquals(additionalHeader, transaction.additionalHeader());
assertEquals(timeStarted, transaction.getTimeStarted());
assertEquals(timeCommitted, transaction.getTimeCommitted());
assertEquals(latestCommittedTxWhenStarted, transaction.getLatestCommittedTxWhenStarted());
}
positionCache.clear();
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method toApply.
private static TransactionToApply toApply(Collection<TransactionRepresentation> transactions) {
TransactionToApply first = null;
TransactionToApply last = null;
for (TransactionRepresentation transactionRepresentation : transactions) {
TransactionToApply transaction = new TransactionToApply(transactionRepresentation, CursorContext.NULL);
if (first == null) {
first = last = transaction;
} else {
last.next(transaction);
last = transaction;
}
}
return first;
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method extractTransactions.
private static List<TransactionRepresentation> extractTransactions(GraphDatabaseAPI db, long txIdToStartOn) throws IOException {
LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
List<TransactionRepresentation> transactions = new ArrayList<>();
try (TransactionCursor cursor = txStore.getTransactions(txIdToStartOn)) {
cursor.forAll(tx -> transactions.add(tx.getTransactionRepresentation()));
}
return transactions;
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method indexShouldIncludeNodesCreatedPreviouslyInBatch.
@Test
void indexShouldIncludeNodesCreatedPreviouslyInBatch() throws Exception {
// GIVEN a transaction stream leading up to this issue
// perform the transactions from db-level and extract the transactions as commands
// so that they can be applied batch-wise they way we'd like to later.
List<TransactionRepresentation> transactions;
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
// We don't want to include any transactions that has been run on start-up when applying to the new database later.
long txIdToStartFrom = getLastClosedTransactionId(db) + 1;
// a bunch of nodes (to have the index population later on to decide to use label scan for population)
String nodeN = "our guy";
String otherNode = "just to create the tokens";
try {
try (Transaction tx = db.beginTx()) {
tx.createNode(LABEL).setProperty(PROPERTY_KEY, otherNode);
for (int i = 0; i < 10_000; i++) {
tx.createNode();
}
tx.commit();
}
// node N
try (Transaction tx = db.beginTx()) {
tx.createNode(LABEL).setProperty(PROPERTY_KEY, nodeN);
tx.commit();
}
// uniqueness constraint affecting N
try (Transaction tx = db.beginTx()) {
tx.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
tx.commit();
}
transactions = extractTransactions(db, txIdToStartFrom);
} finally {
managementService.shutdown();
}
managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
TransactionCommitProcess commitProcess = db.getDependencyResolver().resolveDependency(TransactionCommitProcess.class);
try {
int cutoffIndex = findCutoffIndex(transactions);
commitProcess.commit(toApply(transactions.subList(0, cutoffIndex)), CommitEvent.NULL, EXTERNAL);
// WHEN applying the two transactions (node N and the constraint) in the same batch
commitProcess.commit(toApply(transactions.subList(cutoffIndex, transactions.size())), CommitEvent.NULL, EXTERNAL);
// THEN node N should've ended up in the index too
try (Transaction tx = db.beginTx()) {
// just to verify
assertNotNull(singleOrNull(tx.findNodes(LABEL, PROPERTY_KEY, otherNode)), "Verification node not found");
assertNotNull(singleOrNull(tx.findNodes(LABEL, PROPERTY_KEY, nodeN)), "Node N not found");
tx.commit();
}
} finally {
managementService.shutdown();
}
}
Aggregations