public byte[] toBytes(){ byte[] configData = this.snapshot.getLastConfig().toBytes(); int size = Long.BYTES * 3 + configData.length + Integer.BYTES * 2 + data.length + 1; ByteBuffer buffer = ByteBuffer.allocate(size); buffer.putLong(snapshot.getLastLogIndex()); buffer.putLong(snapshot.getLastLogTerm()); buffer.putInt(configData.length); buffer.put(configData); buffer.putLong(this.offset); buffer.putInt(this.data.length); buffer.put(this.data); buffer.put(this.done ? (byte)1 : (byte)0); return buffer.array(); }
public byte[] toBytes(){ byte[] configData = this.snapshot.getLastConfig().toBytes(); int size = Long.BYTES * 3 + configData.length + Integer.BYTES * 2 + data.length + 1; ByteBuffer buffer = ByteBuffer.allocate(size); buffer.putLong(snapshot.getLastLogIndex()); buffer.putLong(snapshot.getLastLogTerm()); buffer.putInt(configData.length); buffer.put(configData); buffer.putLong(this.offset); buffer.putInt(this.data.length); buffer.put(this.data); buffer.put(this.done ? (byte)1 : (byte)0); return buffer.array(); }
public byte[] toBytes(){ byte[] configData = this.snapshot.getLastConfig().toBytes(); int size = Long.BYTES * 3 + configData.length + Integer.BYTES * 2 + data.length + 1; ByteBuffer buffer = ByteBuffer.allocate(size); buffer.putLong(snapshot.getLastLogIndex()); buffer.putLong(snapshot.getLastLogTerm()); buffer.putInt(configData.length); buffer.put(configData); buffer.putLong(this.offset); buffer.putInt(this.data.length); buffer.put(this.data); buffer.put(this.done ? (byte)1 : (byte)0); return buffer.array(); }
@Override public void saveSnapshotData(Snapshot snapshot, long offset, byte[] data) { Path filePath = this.snapshotStore.resolve(String.format("%d-%d.s", snapshot.getLastLogIndex(), snapshot.getLastLogTerm())); try{ if(!Files.exists(filePath)){ Files.write(this.snapshotStore.resolve(String.format("%d.cnf", snapshot.getLastLogIndex())), snapshot.getLastConfig().toBytes(), StandardOpenOption.CREATE); } RandomAccessFile snapshotFile = new RandomAccessFile(filePath.toString(), "rw"); snapshotFile.seek(offset); snapshotFile.write(data); snapshotFile.close(); }catch(Exception error){ throw new RuntimeException(error.getMessage()); } }
@Override public void saveSnapshotData(Snapshot snapshot, long offset, byte[] data) { Path filePath = this.snapshotStore.resolve(String.format("%d-%d.s", snapshot.getLastLogIndex(), snapshot.getLastLogTerm())); try{ if(!Files.exists(filePath)){ Files.write(this.snapshotStore.resolve(String.format("%d.cnf", snapshot.getLastLogIndex())), snapshot.getLastConfig().toBytes(), StandardOpenOption.CREATE); } RandomAccessFile snapshotFile = new RandomAccessFile(filePath.toString(), "rw"); snapshotFile.seek(offset); snapshotFile.write(data); snapshotFile.close(); }catch(Exception error){ throw new RuntimeException(error.getMessage()); } }
try{ if(!Files.exists(filePath)){ Files.write(this.snapshotStore.resolve(String.format("%d.cnf", snapshot.getLastLogIndex())), snapshot.getLastConfig().toBytes(), StandardOpenOption.CREATE);
try{ if(!Files.exists(filePath)){ Files.write(this.snapshotStore.resolve(String.format("%d.cnf", snapshot.getLastLogIndex())), snapshot.getLastConfig().toBytes(), StandardOpenOption.CREATE);
config = lastSnapshot.getLastConfig(); }else if(config.getLogIndex() > indexCommitted && config.getLastLogIndex() == 0){ this.logger.error("BUG!!! stop the system, there must be a configuration at index one");
this.reconfigure(snapshotSyncRequest.getSnapshot().getLastConfig()); this.context.getServerStateManager().saveClusterConfiguration(this.config); this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex());
config = lastSnapshot.getLastConfig(); }else if(config.getLogIndex() > indexCommitted && config.getLastLogIndex() == 0){ this.logger.error("BUG!!! stop the system, there must be a configuration at index one");
config = lastSnapshot.getLastConfig(); }else if(config.getLogIndex() > indexCommitted && config.getLastLogIndex() == 0){ this.logger.error("BUG!!! stop the system, there must be a configuration at index one");
this.reconfigure(snapshotSyncRequest.getSnapshot().getLastConfig()); this.context.getServerStateManager().saveClusterConfiguration(this.config); this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex());
this.reconfigure(snapshotSyncRequest.getSnapshot().getLastConfig()); this.context.getServerStateManager().saveClusterConfiguration(this.config); this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex());