Skip to content

Commit 4cd50af

Browse files
committed
[core] Introduce 'index-file-in-data-file-dir' to put index files in data dir
1 parent 238386a commit 4cd50af

File tree

49 files changed

+532
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+532
-233
lines changed

docs/layouts/shortcodes/generated/core_configuration.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@
542542
<td>String</td>
543543
<td>Used to specify the end tag (inclusive), and Paimon will find an earlier tag and return changes between them. If the tag doesn't exist or the earlier tag doesn't exist, return empty. This option requires 'tag.creation-period' and 'tag.period-formatter' configured.</td>
544544
</tr>
545+
<tr>
546+
<td><h5>index-file-in-data-file-dir</h5></td>
547+
<td style="word-wrap: break-word;">false</td>
548+
<td>Boolean</td>
549+
<td>Whether index file in data file directory.</td>
550+
</tr>
545551
<tr>
546552
<td><h5>local-merge-buffer-size</h5></td>
547553
<td style="word-wrap: break-word;">(none)</td>

paimon-api/src/main/java/org/apache/paimon/CoreOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,13 @@ public InlineElement getDescription() {
19431943
.noDefaultValue()
19441944
.withDescription("Whether ignore empty commit.");
19451945

1946+
@Immutable
1947+
public static final ConfigOption<Boolean> INDEX_FILE_IN_DATA_FILE_DIR =
1948+
key("index-file-in-data-file-dir")
1949+
.booleanType()
1950+
.defaultValue(false)
1951+
.withDescription("Whether index file in data file directory.");
1952+
19461953
private final Options options;
19471954

19481955
public CoreOptions(Map<String, String> options) {
@@ -2484,6 +2491,10 @@ public boolean disableExplicitTypeCasting() {
24842491
return options.get(DISABLE_EXPLICIT_TYPE_CASTING);
24852492
}
24862493

2494+
public boolean indexFileInDataFileDir() {
2495+
return options.get(INDEX_FILE_IN_DATA_FILE_DIR);
2496+
}
2497+
24872498
public LookupStrategy lookupStrategy() {
24882499
return LookupStrategy.from(
24892500
mergeEngine().equals(MergeEngine.FIRST_ROW),

paimon-common/src/main/java/org/apache/paimon/utils/IntFileUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ public void close() throws IOException {
4646
};
4747
}
4848

49-
public static void writeInts(FileIO fileIO, Path path, IntIterator input) throws IOException {
49+
public static int writeInts(FileIO fileIO, Path path, IntIterator input) throws IOException {
5050
try (FastBufferedOutputStream out =
5151
new FastBufferedOutputStream(fileIO.newOutputStream(path, false));
5252
IntIterator iterator = input) {
53+
int count = 0;
5354
while (true) {
5455
try {
5556
writeInt(out, iterator.next());
57+
count++;
5658
} catch (EOFException ignored) {
57-
break;
59+
return count;
5860
}
5961
}
6062
}

paimon-core/src/main/java/org/apache/paimon/AbstractFileStore.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ protected FileStorePathFactory pathFactory(CoreOptions options, String format) {
131131
options.fileSuffixIncludeCompression(),
132132
options.fileCompression(),
133133
options.dataFilePathDirectory(),
134-
createExternalPaths());
134+
createExternalPaths(),
135+
options.indexFileInDataFileDir());
135136
}
136137

137138
private List<Path> createExternalPaths() {

paimon-core/src/main/java/org/apache/paimon/compact/CompactDeletionFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public CompactDeletionFile mergeOldFile(CompactDeletionFile old) {
9292
@Override
9393
public void clean() {
9494
if (deletionFile != null) {
95-
dvIndexFile.delete(deletionFile.fileName());
95+
dvIndexFile.delete(deletionFile);
9696
}
9797
}
9898
}

paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionFileWriter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.paimon.fs.Path;
2323
import org.apache.paimon.index.DeletionVectorMeta;
2424
import org.apache.paimon.index.IndexFileMeta;
25+
import org.apache.paimon.index.IndexPathFactory;
2526

2627
import java.io.Closeable;
2728
import java.io.DataOutputStream;
@@ -35,11 +36,13 @@
3536
public class DeletionFileWriter implements Closeable {
3637

3738
private final Path path;
39+
private final boolean isExternalPath;
3840
private final DataOutputStream out;
3941
private final LinkedHashMap<String, DeletionVectorMeta> dvMetas;
4042

41-
public DeletionFileWriter(Path path, FileIO fileIO) throws IOException {
42-
this.path = path;
43+
public DeletionFileWriter(IndexPathFactory pathFactory, FileIO fileIO) throws IOException {
44+
this.path = pathFactory.newPath();
45+
this.isExternalPath = pathFactory.isExternalPath();
4346
this.out = new DataOutputStream(fileIO.newOutputStream(path, true));
4447
out.writeByte(VERSION_ID_V1);
4548
this.dvMetas = new LinkedHashMap<>();
@@ -63,6 +66,11 @@ public void close() throws IOException {
6366

6467
public IndexFileMeta result() {
6568
return new IndexFileMeta(
66-
DELETION_VECTORS_INDEX, path.getName(), getPos(), dvMetas.size(), dvMetas);
69+
DELETION_VECTORS_INDEX,
70+
path.getName(),
71+
getPos(),
72+
dvMetas.size(),
73+
dvMetas,
74+
isExternalPath ? path.toString() : null);
6775
}
6876
}

paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorIndexFileWriter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import org.apache.paimon.fs.FileIO;
2222
import org.apache.paimon.index.IndexFileMeta;
23+
import org.apache.paimon.index.IndexPathFactory;
2324
import org.apache.paimon.options.MemorySize;
24-
import org.apache.paimon.utils.PathFactory;
2525

2626
import java.io.IOException;
2727
import java.util.ArrayList;
@@ -33,12 +33,12 @@
3333
/** Writer for deletion vector index file. */
3434
public class DeletionVectorIndexFileWriter {
3535

36-
private final PathFactory indexPathFactory;
36+
private final IndexPathFactory indexPathFactory;
3737
private final FileIO fileIO;
3838
private final long targetSizeInBytes;
3939

4040
public DeletionVectorIndexFileWriter(
41-
FileIO fileIO, PathFactory pathFactory, MemorySize targetSizePerIndexFile) {
41+
FileIO fileIO, IndexPathFactory pathFactory, MemorySize targetSizePerIndexFile) {
4242
this.indexPathFactory = pathFactory;
4343
this.fileIO = fileIO;
4444
this.targetSizeInBytes = targetSizePerIndexFile.getBytes();
@@ -53,7 +53,7 @@ public DeletionVectorIndexFileWriter(
5353
*/
5454
public IndexFileMeta writeSingleFile(Map<String, DeletionVector> input) throws IOException {
5555

56-
DeletionFileWriter writer = new DeletionFileWriter(indexPathFactory.newPath(), fileIO);
56+
DeletionFileWriter writer = new DeletionFileWriter(indexPathFactory, fileIO);
5757
try {
5858
for (Map.Entry<String, DeletionVector> entry : input.entrySet()) {
5959
writer.write(entry.getKey(), entry.getValue());
@@ -79,7 +79,7 @@ public List<IndexFileMeta> writeWithRolling(Map<String, DeletionVector> input)
7979

8080
private IndexFileMeta tryWriter(Iterator<Map.Entry<String, DeletionVector>> iterator)
8181
throws IOException {
82-
DeletionFileWriter writer = new DeletionFileWriter(indexPathFactory.newPath(), fileIO);
82+
DeletionFileWriter writer = new DeletionFileWriter(indexPathFactory, fileIO);
8383
try {
8484
while (iterator.hasNext()) {
8585
Map.Entry<String, DeletionVector> entry = iterator.next();

paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVectorsIndexFile.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.apache.paimon.index.DeletionVectorMeta;
2525
import org.apache.paimon.index.IndexFile;
2626
import org.apache.paimon.index.IndexFileMeta;
27+
import org.apache.paimon.index.IndexPathFactory;
2728
import org.apache.paimon.options.MemorySize;
2829
import org.apache.paimon.table.source.DeletionFile;
29-
import org.apache.paimon.utils.PathFactory;
3030

3131
import java.io.DataInputStream;
3232
import java.io.IOException;
@@ -51,7 +51,7 @@ public class DeletionVectorsIndexFile extends IndexFile {
5151

5252
public DeletionVectorsIndexFile(
5353
FileIO fileIO,
54-
PathFactory pathFactory,
54+
IndexPathFactory pathFactory,
5555
MemorySize targetSizePerIndexFile,
5656
boolean bitmap64) {
5757
super(fileIO, pathFactory);
@@ -71,13 +71,11 @@ public boolean bitmap64() {
7171
* @throws UncheckedIOException If an I/O error occurs while reading from the file.
7272
*/
7373
public Map<String, DeletionVector> readAllDeletionVectors(IndexFileMeta fileMeta) {
74-
LinkedHashMap<String, DeletionVectorMeta> deletionVectorMetas =
75-
fileMeta.deletionVectorMetas();
74+
LinkedHashMap<String, DeletionVectorMeta> deletionVectorMetas = fileMeta.dvRanges();
7675
checkNotNull(deletionVectorMetas);
7776

78-
String indexFileName = fileMeta.fileName();
7977
Map<String, DeletionVector> deletionVectors = new HashMap<>();
80-
Path filePath = pathFactory.toPath(indexFileName);
78+
Path filePath = pathFactory.toPath(fileMeta);
8179
try (SeekableInputStream inputStream = fileIO.newInputStream(filePath)) {
8280
checkVersion(inputStream);
8381
DataInputStream dataInputStream = new DataInputStream(inputStream);

paimon-core/src/main/java/org/apache/paimon/deletionvectors/append/BaseAppendDeleteFileMaintainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ static AppendDeleteFileMaintainer forUnawareAppend(
8282
.collect(Collectors.toList());
8383
Map<String, DeletionFile> deletionFiles = new HashMap<>();
8484
for (IndexManifestEntry file : manifestEntries) {
85-
LinkedHashMap<String, DeletionVectorMeta> dvMetas =
86-
file.indexFile().deletionVectorMetas();
85+
LinkedHashMap<String, DeletionVectorMeta> dvMetas = file.indexFile().dvRanges();
8786
checkNotNull(dvMetas);
8887
for (DeletionVectorMeta dvMeta : dvMetas.values()) {
8988
deletionFiles.put(

paimon-core/src/main/java/org/apache/paimon/iceberg/IcebergCommitCallback.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,7 @@ private List<IcebergManifestFileMeta> createDvManifestFileMetas(Snapshot snapsho
11471147
return Collections.emptyList();
11481148
}
11491149
for (IndexManifestEntry entry : newIndexes) {
1150-
LinkedHashMap<String, DeletionVectorMeta> dvMetas =
1151-
entry.indexFile().deletionVectorMetas();
1150+
LinkedHashMap<String, DeletionVectorMeta> dvMetas = entry.indexFile().dvRanges();
11521151
Path bucketPath = fileStorePathFactory.bucketPath(entry.partition(), entry.bucket());
11531152
if (dvMetas != null) {
11541153
for (DeletionVectorMeta dvMeta : dvMetas.values()) {

0 commit comments

Comments
 (0)