Skip to content

Commit 4fb1fbc

Browse files
authored
[Issue #1220] add a toggle switch to control whether Retina is enabled (#1227)
1 parent 300355f commit 4fb1fbc

File tree

9 files changed

+78
-40
lines changed

9 files changed

+78
-40
lines changed

pixels-cli/src/main/java/io/pixelsdb/pixels/cli/executor/CompactExecutor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,21 @@ public void execute(Namespace ns, String command) throws Exception
214214
while (!compactExecutor.awaitTermination(100, TimeUnit.SECONDS));
215215
metadataService.addFiles(compactFiles);
216216

217-
Iterator<File> fileIterator = compactFiles.iterator();
218-
Iterator<Path> pathIterator = compactPaths.iterator();
219-
while (fileIterator.hasNext() && pathIterator.hasNext())
217+
if (retinaService.isEnabled())
220218
{
221-
File file = fileIterator.next();
222-
Path path = pathIterator.next();
223-
try
219+
Iterator<File> fileIterator = compactFiles.iterator();
220+
Iterator<Path> pathIterator = compactPaths.iterator();
221+
while (fileIterator.hasNext() && pathIterator.hasNext())
224222
{
225-
retinaService.addVisibility(File.getFilePath(path, file));
226-
} catch (RetinaException e)
227-
{
228-
System.out.println("add visibility for compact file '" + file + "' failed");
223+
File file = fileIterator.next();
224+
Path path = pathIterator.next();
225+
try
226+
{
227+
retinaService.addVisibility(File.getFilePath(path, file));
228+
} catch (RetinaException e)
229+
{
230+
System.out.println("add visibility for compact file '" + file + "' failed");
231+
}
229232
}
230233
}
231234

pixels-cli/src/main/java/io/pixelsdb/pixels/cli/executor/LoadExecutor.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,17 @@ public void execute(Namespace ns, String command) throws Exception
100100
NodeProto.NodeInfo nodeInfo = loadedInfo.loadedRetinaNode;
101101
if(nodeInfo == null)
102102
{
103-
defaultRetinaService.addVisibility(File.getFilePath(path, file));
103+
if (defaultRetinaService.isEnabled())
104+
{
105+
defaultRetinaService.addVisibility(File.getFilePath(path, file));
106+
}
104107
} else
105108
{
106109
RetinaService retinaService = RetinaService.CreateInstance(nodeInfo.getAddress(), retinaServerPort);
107-
retinaService.addVisibility(File.getFilePath(path, file));
110+
if (retinaService.isEnabled())
111+
{
112+
retinaService.addVisibility(File.getFilePath(path, file));
113+
}
108114
}
109115

110116
} catch (RetinaException e)

pixels-common/src/main/java/io/pixelsdb/pixels/common/retina/RetinaService.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public class RetinaService
4949

5050
static
5151
{
52-
String retinaHost = ConfigFactory.Instance().getProperty("retina.server.host");
53-
int retinaPort = Integer.parseInt(ConfigFactory.Instance().getProperty("retina.server.port"));
54-
defaultInstance = new RetinaService(retinaHost, retinaPort);
52+
ConfigFactory config = ConfigFactory.Instance();
53+
String retinaHost = config.getProperty("retina.server.host");
54+
int retinaPort = Integer.parseInt(config.getProperty("retina.server.port"));
55+
boolean enabled = Boolean.parseBoolean(config.getProperty("retina.enable"));
56+
defaultInstance = new RetinaService(retinaHost, retinaPort, enabled);
5557
ShutdownHookManager.Instance().registerShutdownHook(RetinaService.class, false, () -> {
5658
try
5759
{
@@ -91,36 +93,54 @@ public static RetinaService Instance()
9193
public static synchronized RetinaService CreateInstance(String host, int port)
9294
{
9395
HostAddress address = HostAddress.fromParts(host, port);
96+
// For other instances, we also follow the global configuration.
97+
String retinaEnable = ConfigFactory.Instance().getProperty("retina.enable");
98+
boolean enabled = Boolean.parseBoolean(retinaEnable);
9499
return otherInstances.computeIfAbsent(
95-
address, addr -> new RetinaService(addr.getHostText(), addr.getPort())
100+
address, addr -> new RetinaService(addr.getHostText(), addr.getPort(), enabled)
96101
);
97102
}
98103

99104
private final ManagedChannel channel;
100105
private final RetinaWorkerServiceGrpc.RetinaWorkerServiceBlockingStub stub;
101106
private final RetinaWorkerServiceGrpc.RetinaWorkerServiceStub asyncStub;
102107
private boolean isShutdown;
108+
private final boolean enabled;
103109

104-
private RetinaService(String host, int port)
110+
private RetinaService(String host, int port, boolean enabled)
105111
{
106-
assert (host != null);
107-
assert (port > 0 && port <= 65535);
108-
this.channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext()
109-
// .keepAliveTime(1, TimeUnit.SECONDS)
110-
// .keepAliveTimeout(3, TimeUnit.SECONDS)
111-
// .keepAliveWithoutCalls(true)
112-
.build();
113-
this.stub = RetinaWorkerServiceGrpc.newBlockingStub(this.channel);
114-
this.asyncStub = RetinaWorkerServiceGrpc.newStub(this.channel);
112+
this.enabled = enabled;
113+
if (enabled)
114+
{
115+
assert (host != null);
116+
assert (port > 0 && port <= 65535);
117+
this.channel = ManagedChannelBuilder.forAddress(host, port).
118+
usePlaintext().build();
119+
this.stub = RetinaWorkerServiceGrpc.newBlockingStub(this.channel);
120+
this.asyncStub = RetinaWorkerServiceGrpc.newStub(this.channel);
121+
} else
122+
{
123+
this.channel = null;
124+
this.stub = null;
125+
this.asyncStub = null;
126+
}
115127
this.isShutdown = false;
116128
}
117129

130+
public boolean isEnabled()
131+
{
132+
return enabled;
133+
}
134+
118135
private synchronized void shutdown() throws InterruptedException
119136
{
120137
if (!this.isShutdown)
121138
{
122-
// Wait for at most 5 seconds, this should be enough to shut down an RPC client.
123-
this.channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
139+
if (this.channel != null)
140+
{
141+
// Wait for at most 5 seconds, this should be enough to shut down an RPC client.
142+
this.channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
143+
}
124144
this.isShutdown = true;
125145
}
126146
}

pixels-common/src/main/resources/pixels.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ memspl = [1,8,16,32,64]
267267

268268
### pixels-retina - write buffer flush configuration ###
269269

270+
# set to true to enable pixels-retina
271+
retina.enable=false
270272
# number of rows recorded in memTable, must be a multiple of 64
271273
retina.buffer.memTable.size=10240
272274
# the scheme of the storage for retina buffer object storage, e.g., s3, minio

pixels-common/src/test/java/io/pixelsdb/pixels/common/retina/TestRetinaService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class TestRetinaService
6565
@BeforeAll
6666
public static void setUp() throws MetadataException, InterruptedException, JsonProcessingException
6767
{
68+
Assertions.assertTrue(RetinaService.Instance().isEnabled(), "Retina service should be enabled for tests");
6869
MetadataService metadataService = MetadataService.Instance();
6970
Table table = metadataService.getTable(schemaName, tableName);
7071
List<Column> columns = metadataService.getColumns(schemaName, tableName, false);

pixels-core/src/main/java/io/pixelsdb/pixels/core/reader/PixelsRecordReaderBufferImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class PixelsRecordReaderBufferImpl implements PixelsRecordReader
7777

7878
private final long tableId;
7979
private final String retinaBufferStorageFolder;
80+
private final boolean retinaEnabled;
8081

8182
private final TypeDescription typeDescription;
8283
private final int colNum;
@@ -112,6 +113,7 @@ public PixelsRecordReaderBufferImpl(PixelsReaderOption option,
112113
{
113114
ConfigFactory configFactory = ConfigFactory.Instance();
114115
this.retinaBufferStorageFolder = configFactory.getProperty("retina.buffer.object.storage.folder");
116+
this.retinaEnabled = Boolean.parseBoolean(configFactory.getProperty("retina.enable"));
115117

116118
this.option = option;
117119
this.activeMemtableData = activeMemtableData;
@@ -158,7 +160,7 @@ private void checkBeforeRead() throws IOException
158160
}
159161

160162
// check retina
161-
if (visibilityBitmap.size() != fileIds.size() + 1)
163+
if (retinaEnabled && visibilityBitmap != null && visibilityBitmap.size() != fileIds.size() + 1)
162164
{
163165
checkValid = false;
164166
throw new IOException("visibilityBitmap.getSize is " + visibilityBitmap.size() +
@@ -266,7 +268,7 @@ public VectorizedRowBatch readBatch() throws IOException
266268
for (int i = 0; i < curBatchSize; i++)
267269
{
268270
if ((hiddenTimestampVector == null || hiddenTimestampVector.vector[i] <= this.option.getTransTimestamp())
269-
&& (!checkBit(visibilityBitmap.get(fileIdIndex), i)))
271+
&& (!retinaEnabled || visibilityBitmap == null || !checkBit(visibilityBitmap.get(fileIdIndex), i)))
270272
{
271273
selectedRows.set(i);
272274
addedRows++;

pixels-core/src/main/java/io/pixelsdb/pixels/core/reader/PixelsRecordReaderImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ else if (predicate.matchesNone())
501501
targetRGNum = targetRGIdx;
502502

503503
// query visibility bitmap of target row groups
504-
if (this.option.hasValidTransTimestamp())
504+
if (this.option.hasValidTransTimestamp() && retinaService.isEnabled())
505505
{
506506
try
507507
{
@@ -1132,7 +1132,7 @@ public VectorizedRowBatch readBatch(int batchSize, boolean reuse)
11321132
for (int i = 0; i < curBatchSize; i++)
11331133
{
11341134
if ((hiddenTimestampVector == null || hiddenTimestampVector.vector[i] <= this.transTimestamp)
1135-
&& (!checkBit(rgVisibilityBitmaps[curRGIdx], curRowInRG + i)))
1135+
&& (rgVisibilityBitmaps == null || !checkBit(rgVisibilityBitmaps[curRGIdx], curRowInRG + i)))
11361136
{
11371137
selectedRows.set(i);
11381138
addedRows++;
@@ -1475,4 +1475,4 @@ public ChunkId(int rowGroupId, int columnId, long offset, int length)
14751475
this.length = length;
14761476
}
14771477
}
1478-
}
1478+
}

pixels-core/src/test/java/io/pixelsdb/pixels/core/reader/TestPixelsRecordReaderBufferImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void testReadBatch() throws RetinaException, IOException
4949

5050

5151
RetinaService retinaService = RetinaService.Instance();
52+
assert retinaService.isEnabled();
5253
long timeStamp = 100000;
5354
RetinaProto.GetWriterBufferResponse superVersion = retinaService.getWriterBuffer(schemaName, tableName, timeStamp);
5455
TypeDescription typeDescription = null;

pixels-daemon/src/main/java/io/pixelsdb/pixels/daemon/metadata/MetadataServiceImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,17 @@ public void createTable(MetadataProto.CreateTableRequest request,
363363
for(NodeProto.NodeInfo retinaNode : retinaList)
364364
{
365365
RetinaService retinaService = RetinaService.CreateInstance(retinaNode.getAddress(), retinaPort);
366-
if (!retinaService.addWriterBuffer(request.getSchemaName(), request.getTableName()))
366+
if (retinaService.isEnabled())
367367
{
368-
headerBuilder.setErrorCode(METADATA_ADD_RETINA_BUFFER_FAILED)
369-
.setErrorMsg("failed to add retina's writer buffer for table '" +
370-
request.getSchemaName() + "." + request.getTableName() + "'");
371-
} else
372-
{
373-
headerBuilder.setErrorCode(SUCCESS).setErrorMsg("");
368+
if (!retinaService.addWriterBuffer(request.getSchemaName(), request.getTableName()))
369+
{
370+
headerBuilder.setErrorCode(METADATA_ADD_RETINA_BUFFER_FAILED)
371+
.setErrorMsg("failed to add retina's writer buffer for table '" +
372+
request.getSchemaName() + "." + request.getTableName() + "'");
373+
} else
374+
{
375+
headerBuilder.setErrorCode(SUCCESS).setErrorMsg("");
376+
}
374377
}
375378
}
376379
} else

0 commit comments

Comments
 (0)