internal static ICollection <StorageCommand> ExtractCommands(sbyte[] commandBytes) { ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes); NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer); LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); LogEntryCommand entryRead; IList <StorageCommand> commands = new LinkedList <StorageCommand>(); try { while ((entryRead = ( LogEntryCommand )reader.ReadLogEntry(channel)) != null) { commands.Add(entryRead.Command); } } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); // TODO: Handle or throw. } return(commands); }
public override TransactionRepresentation Extract(ByteArrayReplicatedTransaction replicatedTransaction) { ByteBuf buffer = Unpooled.wrappedBuffer(replicatedTransaction.TxBytes); NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(buffer); return(Read(channel)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, java.util.List<Object> out) throws Exception protected internal override void Decode(ChannelHandlerContext ctx, ByteBuf msg, IList <object> @out) { NetworkReadableClosableChannelNetty4 logChannel = new NetworkReadableClosableChannelNetty4(msg); StoreId storeId = StoreIdMarshal.INSTANCE.unmarshal(logChannel); LogEntryReader <NetworkReadableClosableChannelNetty4> reader = new VersionAwareLogEntryReader <NetworkReadableClosableChannelNetty4>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); PhysicalTransactionCursor <NetworkReadableClosableChannelNetty4> transactionCursor = new PhysicalTransactionCursor <NetworkReadableClosableChannelNetty4>(logChannel, reader); transactionCursor.Next(); CommittedTransactionRepresentation tx = transactionCursor.Get(); if (tx != null) { @out.Add(new TxPullResponse(storeId, tx)); } }
internal virtual TransactionRepresentation Read(NetworkReadableClosableChannelNetty4 channel) { try { LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(new RecordStorageCommandReaderFactory(), InvalidLogEntryHandler.STRICT); int authorId = channel.Int; int masterId = channel.Int; long latestCommittedTxWhenStarted = channel.Long; long timeStarted = channel.Long; long timeCommitted = channel.Long; int lockSessionId = channel.Int; int headerLength = channel.Int; sbyte[] header; if (headerLength == 0) { header = ExtraHeader; } else { header = new sbyte[headerLength]; } channel.Get(header, headerLength); LogEntryCommand entryRead; IList <StorageCommand> commands = new LinkedList <StorageCommand>(); while ((entryRead = ( LogEntryCommand )reader.ReadLogEntry(channel)) != null) { commands.Add(entryRead.Command); } PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands); tx.SetHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId); return(tx); } catch (IOException e) { throw new Exception(e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, java.util.List<Object> list) throws Exception public override void Decode(ChannelHandlerContext ctx, ByteBuf buffer, IList <object> list) { ReadableChannel channel = new NetworkReadableClosableChannelNetty4(buffer); ClusterId clusterId = ClusterId.Marshal.INSTANCE.unmarshal(channel); int messageTypeWire = channel.Int; Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type[] values = Enum.GetValues(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type)); Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type messageType = values[messageTypeWire]; MemberId from = RetrieveMember(channel); LazyComposer composer; if (messageType.Equals(VOTE_REQUEST)) { MemberId candidate = RetrieveMember(channel); long term = channel.Long; long lastLogIndex = channel.Long; long lastLogTerm = channel.Long; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(from, term, candidate, lastLogIndex, lastLogTerm)); } else if (messageType.Equals(VOTE_RESPONSE)) { long term = channel.Long; bool voteGranted = channel.Get() == 1; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(from, term, voteGranted)); } else if (messageType.Equals(PRE_VOTE_REQUEST)) { MemberId candidate = RetrieveMember(channel); long term = channel.Long; long lastLogIndex = channel.Long; long lastLogTerm = channel.Long; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Request(from, term, candidate, lastLogIndex, lastLogTerm)); } else if (messageType.Equals(PRE_VOTE_RESPONSE)) { long term = channel.Long; bool voteGranted = channel.Get() == 1; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Response(from, term, voteGranted)); } else if (messageType.Equals(APPEND_ENTRIES_REQUEST)) { // how many long term = channel.Long; long prevLogIndex = channel.Long; long prevLogTerm = channel.Long; long leaderCommit = channel.Long; int entryCount = channel.Int; composer = new AppendEntriesComposer(entryCount, from, term, prevLogIndex, prevLogTerm, leaderCommit); } else if (messageType.Equals(APPEND_ENTRIES_RESPONSE)) { long term = channel.Long; bool success = channel.Get() == 1; long matchIndex = channel.Long; long appendIndex = channel.Long; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(from, term, success, matchIndex, appendIndex)); } else if (messageType.Equals(NEW_ENTRY_REQUEST)) { composer = new NewEntryRequestComposer(from); } else if (messageType.Equals(HEARTBEAT)) { long leaderTerm = channel.Long; long commitIndexTerm = channel.Long; long commitIndex = channel.Long; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(from, leaderTerm, commitIndex, commitIndexTerm)); } else if (messageType.Equals(HEARTBEAT_RESPONSE)) { composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(from)); } else if (messageType.Equals(LOG_COMPACTION_INFO)) { long leaderTerm = channel.Long; long prevIndex = channel.Long; composer = new SimpleMessageComposer(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo(from, leaderTerm, prevIndex)); } else { throw new System.ArgumentException("Unknown message type"); } list.Add(new ClusterIdAwareMessageComposer(composer, clusterId)); _protocol.expect(ContentType.ContentType); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, java.util.List<Object> list) throws Exception public override void Decode(ChannelHandlerContext ctx, ByteBuf buffer, IList <object> list) { ReadableChannel channel = new NetworkReadableClosableChannelNetty4(buffer); ClusterId clusterId = ClusterId.Marshal.INSTANCE.unmarshal(channel); int messageTypeWire = channel.Int; Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type[] values = Enum.GetValues(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type)); Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type messageType = values[messageTypeWire]; MemberId from = RetrieveMember(channel); Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage result; if (messageType.Equals(VOTE_REQUEST)) { MemberId candidate = RetrieveMember(channel); long term = channel.Long; long lastLogIndex = channel.Long; long lastLogTerm = channel.Long; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(from, term, candidate, lastLogIndex, lastLogTerm); } else if (messageType.Equals(VOTE_RESPONSE)) { long term = channel.Long; bool voteGranted = channel.Get() == 1; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(from, term, voteGranted); } else if (messageType.Equals(PRE_VOTE_REQUEST)) { MemberId candidate = RetrieveMember(channel); long term = channel.Long; long lastLogIndex = channel.Long; long lastLogTerm = channel.Long; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Request(from, term, candidate, lastLogIndex, lastLogTerm); } else if (messageType.Equals(PRE_VOTE_RESPONSE)) { long term = channel.Long; bool voteGranted = channel.Get() == 1; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Response(from, term, voteGranted); } else if (messageType.Equals(APPEND_ENTRIES_REQUEST)) { // how many long term = channel.Long; long prevLogIndex = channel.Long; long prevLogTerm = channel.Long; long leaderCommit = channel.Long; long count = channel.Long; RaftLogEntry[] entries = new RaftLogEntry[( int )count]; for (int i = 0; i < count; i++) { long entryTerm = channel.Long; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.core.replication.ReplicatedContent content = marshal.unmarshal(channel); ReplicatedContent content = _marshal.unmarshal(channel); entries[i] = new RaftLogEntry(entryTerm, content); } result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(from, term, prevLogIndex, prevLogTerm, entries, leaderCommit); } else if (messageType.Equals(APPEND_ENTRIES_RESPONSE)) { long term = channel.Long; bool success = channel.Get() == 1; long matchIndex = channel.Long; long appendIndex = channel.Long; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(from, term, success, matchIndex, appendIndex); } else if (messageType.Equals(NEW_ENTRY_REQUEST)) { ReplicatedContent content = _marshal.unmarshal(channel); result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(from, content); } else if (messageType.Equals(HEARTBEAT)) { long leaderTerm = channel.Long; long commitIndexTerm = channel.Long; long commitIndex = channel.Long; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(from, leaderTerm, commitIndex, commitIndexTerm); } else if (messageType.Equals(HEARTBEAT_RESPONSE)) { result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(from); } else if (messageType.Equals(LOG_COMPACTION_INFO)) { long leaderTerm = channel.Long; long prevIndex = channel.Long; result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo(from, leaderTerm, prevIndex); } else { throw new System.ArgumentException("Unknown message type"); } list.Add(Org.Neo4j.causalclustering.core.consensus.RaftMessages_ReceivedInstantClusterIdAwareMessage.of(_clock.instant(), clusterId, result)); }