Skip to content

Commit e7b0477

Browse files
authored
[Issue #1263] revise docs and fix minor problems for main index (#1265)
1 parent 8407bf3 commit e7b0477

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

pixels-common/src/main/java/io/pixelsdb/pixels/common/index/LocalIndexService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ public boolean purgeIndexEntries(long tableId, long indexId, List<IndexProto.Ind
495495
rowLocationFirst.getRgRowOffset(),
496496
rowLocationLast.getRgRowOffset()
497497
);
498+
if (mainIndex.hasCache())
499+
{
500+
mainIndex.flushCache(rowLocationFirst.getFileId());
501+
}
498502
mainIndex.deleteRowIdRange(rowIdRange);
499503
}
500504
return true;

pixels-common/src/main/java/io/pixelsdb/pixels/common/index/MainIndex.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
public interface MainIndex extends Closeable
3939
{
4040
/**
41-
* If we want to add more single point index schemes here, modify this enum.
41+
* If we want to add more main index schemes, modify this enum.
4242
*/
4343
enum Scheme
4444
{
@@ -83,7 +83,7 @@ public boolean equals(Scheme other)
8383
}
8484

8585
/**
86-
* @return the tableId of this mainIndex
86+
* @return the table id of this main index
8787
*/
8888
long getTableId();
8989

@@ -97,7 +97,7 @@ public boolean equals(Scheme other)
9797
boolean hasCache();
9898

9999
/**
100-
* Allocate rowId batch for single point index.
100+
* Allocate row id batch for single point index.
101101
* <br/><b>For better performance, use consistent numRowIds when calling this method.</b>
102102
* @param tableId the table id of single point index
103103
* @param numRowIds the number of row ids to allocate
@@ -136,7 +136,8 @@ public boolean equals(Scheme other)
136136

137137
/**
138138
* Delete a range of row ids from the main index. This method only has effect on the persistent storage
139-
* of the main index.
139+
* of the main index. {@link #flushCache(long fileId)} should be called before this method
140+
* delete the row ids from both cache and persistent storage.
140141
* {@link #getLocation(long)} of a row id within a deleted range returns null.
141142
* @param rowIdRange the row id range to be deleted
142143
* @return true on success
@@ -154,7 +155,7 @@ public boolean equals(Scheme other)
154155
boolean flushCache(long fileId) throws MainIndexException;
155156

156157
/**
157-
* Flush the main index cache if exists and close the main index instance.
158+
* Flush the main index cache (if exists) and close the main index instance.
158159
* This method is to be used by the main index factory to close the
159160
* managed main index instances when the process is shutting down.
160161
* <p/>

pixels-common/src/main/java/io/pixelsdb/pixels/common/index/MainIndexBuffer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ protected IndexProto.RowLocation lookup(long fileId, long rowId) throws MainInde
125125
*/
126126
public IndexProto.RowLocation lookup(long rowId) throws MainIndexException
127127
{
128-
IndexProto.RowLocation location = null;
129-
location = this.indexCache.lookup(rowId);
128+
IndexProto.RowLocation location = this.indexCache.lookup(rowId);
130129
if (location == null)
131130
{
132131
for (Map.Entry<Long, Map<Long, IndexProto.RowLocation>> entry : this.indexBuffer.entrySet())

pixels-common/src/main/java/io/pixelsdb/pixels/common/index/MainIndexCache.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public class MainIndexCache implements Closeable
5252
*/
5353
private final List<Map<Long, IndexProto.RowLocation>> entryCacheBuckets;
5454

55+
/**
56+
* Caches the ranges of row ids and the corresponding locations. The cache elements are of the {@link RowIdRange}
57+
* type. However, we use {@link Object} to support looking up single row ids in this range cache.
58+
* Ranges in this cache may overlap but not duplicate.
59+
*/
5560
private final TreeSet<Object> rangeCache;
5661

5762
public MainIndexCache()
@@ -124,13 +129,17 @@ public void evictAllEntries()
124129
}
125130
}
126131

132+
/**
133+
* Admitting a row id range that is overlapping but not duplicate with existing ranges in this cache is acceptable.
134+
* @param range the range to admit into the cache.
135+
*/
127136
public void admitRange(RowIdRange range)
128137
{
129138
this.rangeCache.add(range);
130139
}
131140

132141
/**
133-
* @param range the range to delete
142+
* @param range the range to delete from the cache
134143
* @return true if the range is found and deleted
135144
*/
136145
public boolean evictRange(RowIdRange range)

pixels-core/src/main/java/io/pixelsdb/pixels/core/vector/VectorColumnVector.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Copyright 2023 PixelsDB.
3+
*
4+
* This file is part of Pixels.
5+
*
6+
* Pixels is free software: you can redistribute it and/or modify
7+
* it under the terms of the Affero GNU General Public License as
8+
* published by the Free Software Foundation, either version 3 of
9+
* the License, or (at your option) any later version.
10+
*
11+
* Pixels is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* Affero GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the Affero GNU General Public
17+
* License along with Pixels. If not, see
18+
* <https://www.gnu.org/licenses/>.
19+
*/
120
package io.pixelsdb.pixels.core.vector;
221

322
import com.google.flatbuffers.FlatBufferBuilder;

pixels-daemon/src/main/java/io/pixelsdb/pixels/daemon/index/IndexServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ public void purgeIndexEntries(IndexProto.PurgeIndexEntriesRequest request,
612612
rowLocationFirst.getRgId(),
613613
rowLocationFirst.getRgRowOffset(),
614614
rowLocationLast.getRgRowOffset());
615+
if (mainIndex.hasCache())
616+
{
617+
mainIndex.flushCache(rowLocationFirst.getFileId());
618+
}
615619
mainIndex.deleteRowIdRange(rowIdRange);
616620
}
617621
else

pixels-daemon/src/main/java/io/pixelsdb/pixels/daemon/transaction/TransServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ private static void pushWatermarks(boolean readOnly)
451451
logger.error("new running transactions obtained backward timestamps, this is illegal");
452452
return;
453453
}
454-
// ush watermark to the new min running transaction timestamp
454+
// push watermark to the new min running transaction timestamp
455455
timestamp = minRunningTransTimestamp;
456456
}
457457
if (timestamp < 0)

pixels-index/pixels-index-main-sqlite/src/main/java/io/pixelsdb/pixels/index/main/sqlite/SqliteMainIndex.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ private IndexProto.RowLocation getRowLocationFromSqlite(long rowId) throws MainI
248248
try
249249
{
250250
RowIdRange rowIdRange = getRowIdRangeFromSqlite(rowId);
251-
// Issue #1150: add the range to cache to accelerate main index lookups
252-
this.indexCache.admitRange(rowIdRange);
253251
if (rowIdRange != null)
254252
{
253+
// Issue #1150: add the range to cache to accelerate main index lookups
254+
this.indexCache.admitRange(rowIdRange);
255+
255256
long rowIdStart = rowIdRange.getRowIdStart();
256257
long fileId = rowIdRange.getFileId();
257258
int rgId = rowIdRange.getRgId();

0 commit comments

Comments
 (0)