Skip to content

Commit 5f063ac

Browse files
committed
Maintain MainIndex
1 parent ed80021 commit 5f063ac

File tree

5 files changed

+55
-23
lines changed

5 files changed

+55
-23
lines changed

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,22 @@ public boolean putPrimaryIndexEntries(long tableId, long indexId, List<IndexProt
184184

185185
// Batch insert into single point index
186186
boolean success = singlePointIndex.putPrimaryEntries(entries);
187+
187188
if (!success)
188189
{
189190
throw new IndexException("failed to put primary entries into single point index, tableId="
190191
+ tableId + ", indexId=" + indexId);
191192
}
192193

194+
MainIndex mainIndex = MainIndexFactory.Instance().getMainIndex(tableId);
195+
196+
for (Boolean mainSuccess : mainIndex.putEntries(entries))
197+
{
198+
if(!mainSuccess)
199+
{
200+
throw new MainIndexException("failed to put entry into main index, tableId: " + tableId);
201+
}
202+
}
193203
return true;
194204
}
195205
catch (SinglePointIndexException e)
@@ -362,16 +372,12 @@ public IndexProto.RowLocation updatePrimaryIndexEntry(IndexProto.PrimaryIndexEnt
362372

363373
// Update the entry in the single point index and get the previous row ID
364374
long prevRowId = singlePointIndex.updatePrimaryEntry(key, indexEntry.getRowId());
365-
375+
IndexProto.RowLocation prevLocation;
366376
if (prevRowId > 0)
367377
{
368378
// Retrieve the previous RowLocation from the main index
369-
IndexProto.RowLocation prevLocation = mainIndex.getLocation(prevRowId);
370-
if (prevLocation != null)
371-
{
372-
return prevLocation;
373-
}
374-
else
379+
prevLocation = mainIndex.getLocation(prevRowId);
380+
if (prevLocation == null)
375381
{
376382
throw new IndexException(
377383
"Failed to get previous row location for rowId=" + prevRowId);
@@ -381,6 +387,12 @@ public IndexProto.RowLocation updatePrimaryIndexEntry(IndexProto.PrimaryIndexEnt
381387
{
382388
return null; // entry not found
383389
}
390+
boolean mainSuccess = mainIndex.putEntry(indexEntry.getRowId(), indexEntry.getRowLocation());
391+
if (!mainSuccess)
392+
{
393+
throw new MainIndexException("failed to put entry into main index for rowId=" + indexEntry.getRowId());
394+
}
395+
return prevLocation;
384396
}
385397
catch (MainIndexException e)
386398
{
@@ -416,6 +428,16 @@ public List<IndexProto.RowLocation> updatePrimaryIndexEntries(long tableId, long
416428
throw new IndexException("Failed to get previous row locations for tableId=" +
417429
tableId + ", indexId=" + indexId);
418430
}
431+
432+
433+
for (Boolean mainSuccess : mainIndex.putEntries(indexEntries))
434+
{
435+
if(!mainSuccess)
436+
{
437+
throw new MainIndexException("failed to update entries in main index: " + tableId);
438+
}
439+
}
440+
419441
return prevRowLocations;
420442
}
421443
catch (MainIndexException e)

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ public void putPrimaryIndexEntries(IndexProto.PutPrimaryIndexEntriesRequest requ
216216
{
217217
builder.setErrorCode(ErrorCode.INDEX_PUT_SINGLE_POINT_INDEX_FAIL);
218218
}
219+
220+
MainIndex mainIndex = MainIndexFactory.Instance().getMainIndex(tableId);
221+
for (Boolean mainSuccess : mainIndex.putEntries(entries))
222+
{
223+
if(!mainSuccess)
224+
{
225+
throw new MainIndexException("failed to put entry into main index");
226+
}
227+
}
219228
}
220229
catch (MainIndexException e)
221230
{
@@ -449,6 +458,10 @@ public void updatePrimaryIndexEntry(IndexProto.UpdatePrimaryIndexEntryRequest re
449458
{
450459
builder.setErrorCode(ErrorCode.INDEX_GET_ROW_LOCATION_FAIL);
451460
}
461+
if(!mainIndex.putEntry(entry.getRowId(), entry.getRowLocation()))
462+
{
463+
throw new MainIndexException("Can't update main index, table id: " + tableId);
464+
}
452465
}
453466
else
454467
{
@@ -497,6 +510,15 @@ public void updatePrimaryIndexEntries(IndexProto.UpdatePrimaryIndexEntriesReques
497510
{
498511
builder.setErrorCode(ErrorCode.INDEX_ENTRY_NOT_FOUND);
499512
}
513+
514+
for (Boolean mainSuccess : mainIndex.putEntries(entries))
515+
{
516+
if(!mainSuccess)
517+
{
518+
throw new MainIndexException("failed to put entry into main index");
519+
}
520+
}
521+
500522
}
501523
catch (MainIndexException e)
502524
{

pixels-index/pixels-index-memory/src/main/java/io/pixelsdb/pixels/index/memory/MemoryIndex.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ public boolean putEntry(IndexProto.IndexKey key, long rowId) throws SinglePointI
140140
}
141141

142142
@Override
143-
public boolean putPrimaryEntries(List<IndexProto.PrimaryIndexEntry> entries) throws MainIndexException, SinglePointIndexException
143+
public boolean putPrimaryEntries(List<IndexProto.PrimaryIndexEntry> entries) throws SinglePointIndexException
144144
{
145145
checkClosed();
146146
if (!unique)
147147
{
148148
throw new SinglePointIndexException("putPrimaryEntries can only be called on unique indexes");
149149
}
150-
MainIndex mainIndex = MainIndexFactory.Instance().getMainIndex(tableId);
151-
mainIndex.putEntries(entries);
152150
for (IndexProto.PrimaryIndexEntry entry : entries)
153151
{
154152
CompositeKey baseKey = extractBaseKey(entry.getIndexKey());

pixels-index/pixels-index-rocksdb/src/main/java/io/pixelsdb/pixels/index/rocksdb/RocksDBIndex.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222
import com.google.common.collect.ImmutableList;
2323
import com.google.protobuf.ByteString;
24-
import io.pixelsdb.pixels.common.exception.MainIndexException;
2524
import io.pixelsdb.pixels.common.exception.SinglePointIndexException;
26-
import io.pixelsdb.pixels.common.index.MainIndex;
27-
import io.pixelsdb.pixels.common.index.MainIndexFactory;
2825
import io.pixelsdb.pixels.common.index.SinglePointIndex;
2926
import io.pixelsdb.pixels.index.IndexProto;
3027
import org.apache.commons.io.FileUtils;
@@ -101,7 +98,7 @@ public boolean isUnique()
10198
}
10299

103100
@Override
104-
public long getUniqueRowId(IndexProto.IndexKey key) throws SinglePointIndexException
101+
public long getUniqueRowId(IndexProto.IndexKey key)
105102
{
106103
// Get prefix
107104
byte[] keyBytes = toKeyBytes(key);
@@ -185,7 +182,7 @@ public boolean putEntry(IndexProto.IndexKey key, long rowId) throws SinglePointI
185182

186183
@Override
187184
public boolean putPrimaryEntries(List<IndexProto.PrimaryIndexEntry> entries)
188-
throws SinglePointIndexException, MainIndexException
185+
throws SinglePointIndexException
189186
{
190187
try (WriteBatch writeBatch = new WriteBatch())
191188
{
@@ -202,8 +199,6 @@ public boolean putPrimaryEntries(List<IndexProto.PrimaryIndexEntry> entries)
202199
// Write to RocksDB
203200
writeBatch.put(keyBytes, valueBytes);
204201
}
205-
MainIndex mainIndex = MainIndexFactory.Instance().getMainIndex(tableId);
206-
mainIndex.putEntries(entries);
207202
rocksDB.write(writeOptions, writeBatch);
208203
return true;
209204
}

pixels-index/pixels-index-rockset/src/main/java/io/pixelsdb/pixels/index/rockset/RocksetIndex.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
package io.pixelsdb.pixels.index.rockset;
2121

2222
import com.google.common.collect.ImmutableList;
23-
import io.pixelsdb.pixels.common.exception.MainIndexException;
2423
import io.pixelsdb.pixels.common.exception.SinglePointIndexException;
25-
import io.pixelsdb.pixels.common.index.MainIndex;
26-
import io.pixelsdb.pixels.common.index.MainIndexFactory;
2724
import io.pixelsdb.pixels.common.index.SinglePointIndex;
2825
import io.pixelsdb.pixels.index.IndexProto;
2926
import org.apache.logging.log4j.LogManager;
@@ -284,14 +281,12 @@ public boolean putEntry(IndexProto.IndexKey key, long rowId) throws SinglePointI
284281

285282
@Override
286283
public boolean putPrimaryEntries(List<IndexProto.PrimaryIndexEntry> entries)
287-
throws SinglePointIndexException, MainIndexException
284+
throws SinglePointIndexException
288285
{
289286
long wb = 0;
290287
try
291288
{
292289
wb = WriteBatchCreate();
293-
MainIndex mainIndex = MainIndexFactory.Instance().getMainIndex(tableId);
294-
mainIndex.putEntries(entries);
295290
for (IndexProto.PrimaryIndexEntry entry : entries)
296291
{
297292
IndexProto.IndexKey key = entry.getIndexKey();

0 commit comments

Comments
 (0)