@Override protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException { try (WriteBatch writeBatch = levelDB.createWriteBatch()) { while (entries.hasNext()) { RawMessageTableEntry entry = entries.next(); byte[] rowKey = entry.getKey(); // LevelDB doesn't make copies, and since we reuse RawMessageTableEntry object, we need to create copies. writeBatch.put(Arrays.copyOf(rowKey, rowKey.length), encodeValue(entry.getTxPtr(), entry.getPayload())); } levelDB.write(writeBatch, WRITE_OPTIONS); } catch (DBException ex) { throw new IOException(ex); } }
@Override protected void persist(Iterator<RawMessageTableEntry> entries) throws IOException { try (WriteBatch writeBatch = levelDB.createWriteBatch()) { while (entries.hasNext()) { RawMessageTableEntry entry = entries.next(); byte[] rowKey = entry.getKey(); // LevelDB doesn't make copies, and since we reuse RawMessageTableEntry object, we need to create copies. writeBatch.put(Arrays.copyOf(rowKey, rowKey.length), encodeValue(entry.getTxPtr(), entry.getPayload())); } levelDB.write(writeBatch, WRITE_OPTIONS); } catch (DBException ex) { throw new IOException(ex); } }
@Override protected void rollback(byte[] startKey, byte[] stopKey, byte[] txWritePtr) throws IOException { WriteBatch writeBatch = levelDB.createWriteBatch(); try (CloseableIterator<Map.Entry<byte[], byte[]>> rowIterator = new DBScanIterator(levelDB, startKey, stopKey)) { while (rowIterator.hasNext()) { Map.Entry<byte[], byte[]> rowValue = rowIterator.next(); byte[] value = rowValue.getValue(); Map<String, byte[]> columns = decodeValue(value); writeBatch.put(rowValue.getKey(), encodeValue(txWritePtr, columns.get(PAYLOAD_COL))); } } try { levelDB.write(writeBatch, WRITE_OPTIONS); } catch (DBException ex) { throw new IOException(ex); } }
@Override protected void rollback(byte[] startKey, byte[] stopKey, byte[] txWritePtr) throws IOException { WriteBatch writeBatch = levelDB.createWriteBatch(); try (CloseableIterator<Map.Entry<byte[], byte[]>> rowIterator = new DBScanIterator(levelDB, startKey, stopKey)) { while (rowIterator.hasNext()) { Map.Entry<byte[], byte[]> rowValue = rowIterator.next(); byte[] value = rowValue.getValue(); Map<String, byte[]> columns = decodeValue(value); writeBatch.put(rowValue.getKey(), encodeValue(txWritePtr, columns.get(PAYLOAD_COL))); } } try { levelDB.write(writeBatch, WRITE_OPTIONS); } catch (DBException ex) { throw new IOException(ex); } }