Skip to content

Commit

Permalink
Merge pull request #248 from espaillato/patch-2
Browse files Browse the repository at this point in the history
Update BinLogWriter.java
  • Loading branch information
ar authored Jun 24, 2022
2 parents 6449f59 + 9034c95 commit d9f8e4f
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions modules/binlog/src/main/java/org/jpos/binlog/BinLogWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,43 @@ public void cutover () throws IOException {
if (readStatus() != Status.OPEN)
throw new IOException ("BinLog not open");
AsynchronousFileChannel newRaf = openOrCreateFile(dir, ++fileNumber);
ByteBuffer index = ByteBuffer.allocate(4);
index.putInt(fileNumber);
index.flip();
try {
int write = raf.write(index, NEXT_LOG_INDEX_OFFSET).get();
if (write != 4) {
throw new IOException ("Failed to write 4 byte NEXT_LOG_INDEX_OFFSET, return: " + write);
ByteBuffer index = ByteBuffer.allocate(4);
index.putInt(fileNumber);
index.flip();
try {
int write = raf.write(index, NEXT_LOG_INDEX_OFFSET).get();
if (write != 4) {
throw new IOException ("Failed to write 4 byte NEXT_LOG_INDEX_OFFSET, return: " + write);
}
} catch (InterruptedException e) {
throw new IOException (e.getMessage());
} catch (ExecutionException e) {
throw new IOException (e.getMessage());
}
} catch (InterruptedException e) {
throw new IOException (e.getMessage());
} catch (ExecutionException e) {
throw new IOException (e.getMessage());
}
ByteBuffer status = ByteBuffer.allocate(2);
status.putShort(Status.CLOSED.shortValue());
status.flip();
try {
int write = raf.write(status, STATUS_OFFSET).get();
if (write != 2) {
throw new IOException ("Failed to write 2 byte STATUS_OFFSET, return: " + write);
ByteBuffer status = ByteBuffer.allocate(2);
status.putShort(Status.CLOSED.shortValue());
status.flip();
try {
int write = raf.write(status, STATUS_OFFSET).get();
if (write != 2) {
throw new IOException ("Failed to write 2 byte STATUS_OFFSET, return: " + write);
}
} catch (InterruptedException e) {
throw new IOException (e.getMessage());
} catch (ExecutionException e) {
throw new IOException (e.getMessage());
}
channel.force(false);
raf = newRaf;
} finally {
lock.release();
if (newRaf == raf) {
channel.close();
} else {
newRaf.close();
}
} catch (InterruptedException e) {
throw new IOException (e.getMessage());
} catch (ExecutionException e) {
throw new IOException (e.getMessage());
}
channel.force(false);
raf = newRaf;
lock.release();
} else {
throw new IOException ("Failed to acquire file lock");
}
Expand Down

0 comments on commit d9f8e4f

Please sign in to comment.