Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segment file name radix #764

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.replicator.nrt.CopyState;
import org.apache.lucene.replicator.nrt.FileMetaData;
import org.slf4j.Logger;
Expand All @@ -52,7 +53,6 @@
*/
public class NrtDataManager implements Closeable {
private static final Logger logger = LoggerFactory.getLogger(NrtDataManager.class);
private static final String SEGMENTS_FILE_FORMAT = "segments_%d";
private final String serviceName;
private final String ephemeralId;
private final String indexIdentifier;
Expand Down Expand Up @@ -205,7 +205,9 @@ public void restoreIfNeeded(Path shardDataDir) throws IOException {
@VisibleForTesting
static void writeSegmentsFile(byte[] segmentBytes, long gen, Path shardDataDir)
throws IOException {
Path segmentsFile = shardDataDir.resolve(String.format(SEGMENTS_FILE_FORMAT, gen));
String segmentsFileName =
IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS, "", gen);
Path segmentsFile = shardDataDir.resolve(segmentsFileName);
try (OutputStream os = new FileOutputStream(segmentsFile.toFile())) {
os.write(segmentBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public void testRestoreIfNeeded_exist_keepExisting() throws IOException {
@Test
public void testWriteSegmentsFile() throws IOException {
NrtDataManager.writeSegmentsFile(new byte[] {1, 2, 3, 4, 5}, 14, folder.getRoot().toPath());
assertArrayEquals(new String[] {"segments_14"}, folder.getRoot().list());
byte[] fileBytes = Files.readAllBytes(folder.getRoot().toPath().resolve("segments_14"));
assertArrayEquals(new String[] {"segments_e"}, folder.getRoot().list());
byte[] fileBytes = Files.readAllBytes(folder.getRoot().toPath().resolve("segments_e"));
assertArrayEquals(new byte[] {1, 2, 3, 4, 5}, fileBytes);
}

Expand Down
Loading