try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(256); final DataOutputStream dos = new DataOutputStream(baos)) { writeRecord(record, 0L, dos); serialized = baos.toByteArray(); cipherBytes = encrypt(serialized, eventId); } catch (EncryptionException e) { logger.error("Encountered an error: ", e); writeStart = System.nanoTime(); try { recordIdentifier = record.getEventId() == -1L ? getIdGenerator().getAndIncrement() : record.getEventId(); startBytes = getBytesWritten(); ensureStreamState(recordIdentifier, startBytes); final DataOutputStream out = getBufferedOutputStream(); final int recordIdOffset = (int) (recordIdentifier - getFirstEventId()); out.writeInt(recordIdOffset); out.writeInt(cipherBytes.length); out.write(cipherBytes); getRecordCount().incrementAndGet(); endBytes = getBytesWritten(); } catch (final IOException ioe) { markDirty(); throw ioe; getWriteTimes().add(new TimestampedLong(writeNanos));
private void printStats() { final long sixtySecondsAgo = System.currentTimeMillis() - 60000L; final Long writeNanosLast60 = getWriteTimes().getAggregateValue(sixtySecondsAgo).getValue(); final Long lockNanosLast60 = getLockTimes().getAggregateValue(sixtySecondsAgo).getValue(); final Long serializeNanosLast60 = getSerializeTimes().getAggregateValue(sixtySecondsAgo).getValue(); final Long encryptNanosLast60 = getEncryptTimes().getAggregateValue(sixtySecondsAgo).getValue(); final Long bytesWrittenLast60 = getBytesWrittenBuffer().getAggregateValue(sixtySecondsAgo).getValue(); logger.debug("In the last 60 seconds, have spent {} millis writing to file ({} MB), {} millis waiting on synchronize block, {} millis serializing events, {} millis encrypting events", TimeUnit.NANOSECONDS.toMillis(writeNanosLast60), bytesWrittenLast60 / 1024 / 1024, TimeUnit.NANOSECONDS.toMillis(lockNanosLast60), TimeUnit.NANOSECONDS.toMillis(serializeNanosLast60), TimeUnit.NANOSECONDS.toMillis(encryptNanosLast60)); }
try { final TocWriter tocWriter = createToc ? new StandardTocWriter(TocUtil.getTocFile(file), false, false) : null; return new EncryptedSchemaRecordWriter(file, idGenerator, tocWriter, compressed, BLOCK_SIZE, idLookup, provenanceEventEncryptor, getConfig().getDebugFrequency()); } catch (EncryptionException e) { logger.error("Encountered an error building the schema record writer factory: ", e);