@@ -363,7 +363,7 @@ void writeFieldInfos(long id, byte[] rawBytes) {
363363 throw new RecordCoreArgumentException ("FieldInfo id should never be 0" );
364364 }
365365 byte [] key = fieldInfosSubspace .pack (id );
366- byte [] value = serializer . encodeFieldProtobuf (rawBytes );
366+ byte [] value = encodeFieldProtobuf (rawBytes );
367367 agilityContext .recordSize (LuceneEvents .SizeEvents .LUCENE_WRITE , key .length + value .length );
368368 if (LOGGER .isTraceEnabled ()) {
369369 LOGGER .trace (getLogMessage ("Write lucene stored field infos data" ,
@@ -379,8 +379,8 @@ Stream<NonnullPair<Long, byte[]>> getAllFieldInfosStream() {
379379 agilityContext .apply (aContext -> aContext .ensureActive ().getRange (fieldInfosSubspace .range ()).asList ()))
380380 .stream ()
381381 .map (keyValue -> NonnullPair .of (
382- fieldInfosSubspace .unpack (keyValue .getKey ()).getLong (0 ),
383- serializer . decodeFieldProtobuf (keyValue .getValue ())));
382+ fieldInfosSubspace .unpack (keyValue .getKey ()).getLong (0 ),
383+ decodeFieldProtobuf (keyValue .getValue ())));
384384 }
385385
386386 public CompletableFuture <Integer > getFieldInfosCount () {
@@ -425,7 +425,7 @@ public static boolean isStoredFieldsFile(String name) {
425425 */
426426 public void writeFDBLuceneFileReference (@ Nonnull String name , @ Nonnull FDBLuceneFileReference reference ) {
427427 final byte [] fileReferenceBytes = reference .getBytes ();
428- final byte [] encodedBytes = Objects .requireNonNull (serializer . encode (fileReferenceBytes ));
428+ final byte [] encodedBytes = Objects .requireNonNull (encode (fileReferenceBytes ));
429429 agilityContext .recordSize (LuceneEvents .SizeEvents .LUCENE_WRITE_FILE_REFERENCE , encodedBytes .length );
430430 if (LOGGER .isTraceEnabled ()) {
431431 LOGGER .trace (getLogMessage ("Write lucene file reference" ,
@@ -447,7 +447,7 @@ public void writeFDBLuceneFileReference(@Nonnull String name, @Nonnull FDBLucene
447447 * @return the actual data size written to database with potential compression and encryption applied
448448 */
449449 public int writeData (final long id , final int block , @ Nonnull final byte [] value ) {
450- final byte [] encodedBytes = Objects .requireNonNull (serializer . encode (value ));
450+ final byte [] encodedBytes = Objects .requireNonNull (encode (value ));
451451 agilityContext .increment (LuceneEvents .Counts .LUCENE_BLOCK_WRITES );
452452 //This may not be correct transactionally
453453 agilityContext .recordSize (LuceneEvents .SizeEvents .LUCENE_WRITE , encodedBytes .length );
@@ -471,7 +471,7 @@ public int writeData(final long id, final int block, @Nonnull final byte[] value
471471 */
472472 public void writeStoredFields (@ Nonnull String segmentName , int docID , @ Nonnull final byte [] rawBytes ) {
473473 byte [] key = storedFieldsSubspace .pack (Tuple .from (segmentName , docID ));
474- byte [] value = serializer . encodeFieldProtobuf (rawBytes );
474+ byte [] value = encodeFieldProtobuf (rawBytes );
475475 agilityContext .recordSize (LuceneEvents .SizeEvents .LUCENE_WRITE_STORED_FIELDS , key .length + value .length );
476476 if (LOGGER .isTraceEnabled ()) {
477477 LOGGER .trace (getLogMessage ("Write lucene stored fields data" ,
@@ -562,7 +562,7 @@ private CompletableFuture<byte[]> readBlock(@Nonnull IndexInput requestingInput,
562562 private CompletableFuture <byte []> readData (long id , int block ) {
563563 return agilityContext .instrument (LuceneEvents .Events .LUCENE_FDB_READ_BLOCK ,
564564 agilityContext .get (dataSubspace .pack (Tuple .from (id , block )))
565- .thenApply (serializer ::decode ));
565+ .thenApply (this ::decode ));
566566 }
567567
568568 @ Nonnull
@@ -577,7 +577,7 @@ public byte[] readStoredFields(String segmentName, int docId) {
577577 .addLogInfo (LuceneLogMessageKeys .DOC_ID , docId )
578578 .addLogInfo (LogMessageKeys .KEY , ByteArrayUtil2 .loggable (key ));
579579 }
580- return Objects .requireNonNull (serializer . decodeFieldProtobuf (rawBytes ));
580+ return Objects .requireNonNull (decodeFieldProtobuf (rawBytes ));
581581 }
582582
583583 @ Nonnull
@@ -591,7 +591,7 @@ public List<byte[]> readAllStoredFields(String segmentName) {
591591 .addLogInfo (LogMessageKeys .RANGE_START , ByteArrayUtil2 .loggable (range .begin ))
592592 .addLogInfo (LogMessageKeys .RANGE_END , ByteArrayUtil2 .loggable (range .end ));
593593 }
594- return list .stream ().map (KeyValue ::getValue ).map (serializer ::decodeFieldProtobuf ).collect (Collectors .toList ());
594+ return list .stream ().map (KeyValue ::getValue ).map (this ::decodeFieldProtobuf ).collect (Collectors .toList ());
595595 }
596596
597597 /**
@@ -648,7 +648,7 @@ private CompletableFuture<Void> loadFileReferenceCacheForMemoization() {
648648 agilityContext .recordSize (LuceneEvents .SizeEvents .LUCENE_FILES_COUNT , list .size ());
649649 list .forEach (kv -> {
650650 String name = metaSubspace .unpack (kv .getKey ()).getString (0 );
651- final FDBLuceneFileReference fileReference = Objects .requireNonNull (FDBLuceneFileReference .parseFromBytes (serializer . decode (kv .getValue ())));
651+ final FDBLuceneFileReference fileReference = Objects .requireNonNull (FDBLuceneFileReference .parseFromBytes (decode (kv .getValue ())));
652652 outMap .put (name , fileReference );
653653 if (fileReference .getFieldInfosId () != 0 ) {
654654 fieldInfosCount .computeIfAbsent (fileReference .getFieldInfosId (), key -> new AtomicInteger (0 ))
@@ -939,7 +939,7 @@ public void rename(@Nonnull final String source, @Nonnull final String dest) thr
939939 .addLogInfo (LuceneLogMessageKeys .COMPRESSION_SUPPOSED , serializer .isCompressionEnabled ())
940940 .addLogInfo (LuceneLogMessageKeys .ENCRYPTION_SUPPOSED , serializer .isEncryptionEnabled ());
941941 }
942- byte [] encodedBytes = serializer . encode (value .getBytes ());
942+ byte [] encodedBytes = encode (value .getBytes ());
943943 agilityContext .set (metaSubspace .pack (dest ), encodedBytes );
944944 agilityContext .clear (key );
945945
@@ -1259,4 +1259,34 @@ public String getIndexOption(@Nonnull String key) {
12591259 private FDBDirectoryLockFactory defaultLockFactory (final AgilityContext agilityContext ) {
12601260 return new FDBDirectoryLockFactory (this , Objects .requireNonNullElse (agilityContext .getPropertyValue (LuceneRecordContextProperties .LUCENE_FILE_LOCK_TIME_WINDOW_MILLISECONDS ), 0 ));
12611261 }
1262+
1263+ private byte [] encodeFieldProtobuf (final byte [] bytes ) {
1264+ long startTime = System .nanoTime ();
1265+ byte [] encoded = serializer .encodeFieldProtobuf (bytes );
1266+ agilityContext .recordEvent (LuceneEvents .Waits .WAIT_LUCENE_SERIALIZE , System .nanoTime () - startTime );
1267+ return encoded ;
1268+ }
1269+
1270+ private byte [] decodeFieldProtobuf (final byte [] bytes ) {
1271+ long startTime = System .nanoTime ();
1272+ final byte [] decoded = serializer .decodeFieldProtobuf (bytes );
1273+ agilityContext .recordEvent (LuceneEvents .Waits .WAIT_LUCENE_DESERIALIZE , System .nanoTime () - startTime );
1274+ return decoded ;
1275+ }
1276+
1277+ private byte [] encode (final byte [] bytes ) {
1278+ long startTime = System .nanoTime ();
1279+ final byte [] encoded = serializer .encode (bytes );
1280+ agilityContext .recordEvent (LuceneEvents .Waits .WAIT_LUCENE_SERIALIZE , System .nanoTime () - startTime );
1281+ return encoded ;
1282+ }
1283+
1284+ private byte [] decode (final byte [] bytes ) {
1285+ long startTime = System .nanoTime ();
1286+ final byte [] decoded = serializer .decode (bytes );
1287+ agilityContext .recordEvent (LuceneEvents .Waits .WAIT_LUCENE_DESERIALIZE , System .nanoTime () - startTime );
1288+ return decoded ;
1289+ }
1290+
1291+
12621292}
0 commit comments