| 296 | } |
| 297 | |
| 298 | private synchronized long append(K key, V v) throws IOException { |
| 299 | // core append path for all mutations |
| 300 | |
| 301 | // encode to byte buffer, record length |
| 302 | ByteBuffer payload = encoder.encode(key, v); |
| 303 | lenBuffer.clear(); |
| 304 | lenBuffer.putInt(0, payload.remaining()); |
| 305 | |
| 306 | // create crc checksum |
| 307 | digest.reset(); |
| 308 | digest.update(payload.slice()); |
| 309 | int d = (int) (digest.getValue() & DIGEST_MASK); |
| 310 | digestBuffer.clear(); |
| 311 | digestBuffer.putInt(0, d); |
| 312 | |
| 313 | // return the current write pos |
| 314 | long ret = currentWritePos; |
| 315 | int fp = Integer.BYTES + Integer.BYTES + payload.remaining(); |
| 316 | write(lenBuffer, payload, digestBuffer, fp); |
| 317 | this.currentWritePos = currentWritePos + fp; |
| 318 | entriesOnDisk++; |
| 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | private void write(ByteBuffer len, ByteBuffer arr, ByteBuffer d, int fp) throws IOException { |
| 323 | // write the data into the buffer, flushing if necessary |