2

I want to update a record at specific index. My code did not work. Thank you all

    appender.writeBytes(Bytes.wrapForRead("1234".getBytes()));
    long index = tailer.index();        
    DocumentContext dc = tailer.readingDocument();
    Wire wire = dc.wire();
    Bytes<?> bytes = wire.bytes();
    LOG.info("Before change {}", bytes);
    wire.clear();
    wire.writeBytes(b -> {
        b.write("ccccc".getBytes());
    });
    index = tailer.index() - 1;
    tailer.moveToIndex(index);
    DocumentContext dc2 = tailer.readingDocument();     
    Wire wire2 = dc2.wire();
    Bytes<?> bytes2 = wire2.bytes();
    LOG.info("After Change {}", bytes2);
dragun
  • 21
  • 2

1 Answers1

1

There's no way to edit an entry in the Chronicle Queue. You can only append data at the end. This is a deliberate design choice, and allows to make a lot of optimizations.

Just to give an example: the entries in the queue are written as a stream of bytes, one after the other. If we allow editing, than any edit changing the length of the entry would require shifting all entries following the one being edited which is extremely inefficient.

Dmitry Pisklov
  • 1,196
  • 1
  • 6
  • 16