77
88package org .elasticsearch .xpack .ml .packageloader .action ;
99
10+ import org .apache .logging .log4j .LogManager ;
11+ import org .apache .logging .log4j .Logger ;
1012import org .elasticsearch .ElasticsearchException ;
1113import org .elasticsearch .ElasticsearchStatusException ;
1214import org .elasticsearch .ResourceNotFoundException ;
5658 */
5759final class ModelLoaderUtils {
5860
61+ private static final Logger logger = LogManager .getLogger (ModelLoaderUtils .class );
62+
5963 public static String METADATA_FILE_EXTENSION = ".metadata.json" ;
6064 public static String MODEL_FILE_EXTENSION = ".pt" ;
6165
62- private static ByteSizeValue VOCABULARY_SIZE_LIMIT = new ByteSizeValue (20 , ByteSizeUnit .MB );
66+ private static final ByteSizeValue VOCABULARY_SIZE_LIMIT = new ByteSizeValue (20 , ByteSizeUnit .MB );
6367 private static final String VOCABULARY = "vocabulary" ;
6468 private static final String MERGES = "merges" ;
6569 private static final String SCORES = "scores" ;
@@ -83,6 +87,7 @@ record BytesAndPartIndex(BytesArray bytes, int partIndex) {}
8387 private final AtomicInteger currentPart ;
8488 private final int lastPartNumber ;
8589 private final byte [] buf ;
90+ private final RequestRange range ; // TODO debug only
8691
8792 HttpStreamChunker (URI uri , RequestRange range , int chunkSize ) {
8893 var inputStream = getHttpOrHttpsInputStream (uri , range );
@@ -91,6 +96,7 @@ record BytesAndPartIndex(BytesArray bytes, int partIndex) {}
9196 this .lastPartNumber = range .startPart () + range .numParts ();
9297 this .currentPart = new AtomicInteger (range .startPart ());
9398 this .buf = new byte [chunkSize ];
99+ this .range = range ;
94100 }
95101
96102 // This ctor exists for testing purposes only.
@@ -100,6 +106,7 @@ record BytesAndPartIndex(BytesArray bytes, int partIndex) {}
100106 this .lastPartNumber = range .startPart () + range .numParts ();
101107 this .currentPart = new AtomicInteger (range .startPart ());
102108 this .buf = new byte [chunkSize ];
109+ this .range = range ;
103110 }
104111
105112 public boolean hasNext () {
@@ -113,6 +120,7 @@ public BytesAndPartIndex next() throws IOException {
113120 int read = inputStream .read (buf , bytesRead , chunkSize - bytesRead );
114121 // EOF??
115122 if (read == -1 ) {
123+ logger .debug ("end of stream, " + bytesRead + " bytes read" );
116124 break ;
117125 }
118126 bytesRead += read ;
@@ -122,6 +130,7 @@ public BytesAndPartIndex next() throws IOException {
122130 totalBytesRead .addAndGet (bytesRead );
123131 return new BytesAndPartIndex (new BytesArray (buf , 0 , bytesRead ), currentPart .getAndIncrement ());
124132 } else {
133+ logger .warn ("Empty part in range " + range + ", current part=" + currentPart .get () + ", last part=" + lastPartNumber );
125134 return new BytesAndPartIndex (BytesArray .EMPTY , currentPart .get ());
126135 }
127136 }
0 commit comments