use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class ReplicatedTransactionFactory method read.
public static TransactionRepresentation read(NetworkReadableClosableChannelNetty4 channel, byte[] extraHeader) throws IOException {
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
int authorId = channel.getInt();
int masterId = channel.getInt();
long latestCommittedTxWhenStarted = channel.getLong();
long timeStarted = channel.getLong();
long timeCommitted = channel.getLong();
int lockSessionId = channel.getInt();
int headerLength = channel.getInt();
byte[] header;
if (headerLength == 0) {
header = extraHeader;
} else {
header = new byte[headerLength];
}
channel.get(header, headerLength);
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId);
return tx;
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class ReplicatedTokenHolder method createCommands.
private byte[] createCommands(String tokenName) {
StorageEngine storageEngine = dependencies.resolveDependency(StorageEngine.class);
Collection<StorageCommand> commands = new ArrayList<>();
TransactionState txState = new TxState();
int tokenId = Math.toIntExact(idGeneratorFactory.get(tokenIdType).nextId());
createToken(txState, tokenName, tokenId);
try (StorageStatement statement = storageEngine.storeReadLayer().newStatement()) {
storageEngine.createCommands(commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE);
} catch (CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e) {
throw new RuntimeException("Unable to create token '" + tokenName + "'", e);
}
return ReplicatedTokenRequestSerializer.commandBytes(commands);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class ReplicatedTokenRequestSerializer method extractCommands.
static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
try {
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
} catch (IOException e) {
// TODO: Handle or throw.
e.printStackTrace();
}
return commands;
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class SlaveTransactionCommitProcessTest method setUp.
@Before
public void setUp() {
lastSeenEventIdentifier = new AtomicInteger(-1);
master = mock(Master.class);
requestContext = new RequestContext(10, 11, 12, 13, 14);
reqFactory = new ConstantRequestContextFactory(requestContext) {
@Override
public RequestContext newRequestContext(int eventIdentifier) {
lastSeenEventIdentifier.set(eventIdentifier);
return super.newRequestContext(eventIdentifier);
}
};
response = new LongResponse(42L);
tx = new PhysicalTransactionRepresentation(Collections.<StorageCommand>emptyList());
tx.setHeader(new byte[] {}, 1, 1, 1, 1, 1, 1337);
commitProcess = new SlaveTransactionCommitProcess(master, reqFactory);
}
use of org.neo4j.storageengine.api.StorageCommand in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
Aggregations