Search in sources :

Example 1 with LogReader

use of com.alibaba.graphscope.groot.wal.LogReader in project GraphScope by alibaba.

the class KafkaWalTest method testLogService.

@Test
void testLogService() throws IOException {
    Configs configs = Configs.newBuilder().put(KafkaConfig.KAFKA_SERVERS.getKey(), sharedKafkaTestResource.getKafkaConnectString()).put(KafkaConfig.KAKFA_TOPIC.getKey(), "test_logservice").put(CommonConfig.INGESTOR_QUEUE_COUNT.getKey(), "1").build();
    LogService logService = new KafkaLogService(configs);
    logService.init();
    int queueId = 0;
    long snapshotId = 1L;
    LogWriter writer = logService.createWriter(queueId);
    LogEntry logEntry = new LogEntry(snapshotId, OperationBatch.newBuilder().addOperationBlob(OperationBlob.MARKER_OPERATION_BLOB).build());
    assertEquals(writer.append(logEntry), 0);
    LogReader reader = logService.createReader(queueId, 0);
    ReadLogEntry readLogEntry = reader.readNext();
    reader.close();
    assertAll(() -> assertEquals(readLogEntry.getOffset(), 0), () -> assertEquals(readLogEntry.getLogEntry().getSnapshotId(), snapshotId));
    OperationBatch operationBatch = readLogEntry.getLogEntry().getOperationBatch();
    assertEquals(operationBatch.getOperationCount(), 1);
    assertEquals(operationBatch.getOperationBlob(0), OperationBlob.MARKER_OPERATION_BLOB);
    assertEquals(writer.append(logEntry), 1);
    assertEquals(writer.append(logEntry), 2);
    assertEquals(writer.append(logEntry), 3);
    LogReader readerTail = logService.createReader(queueId, 4);
    assertNull(readerTail.readNext());
    readerTail.close();
    assertThrows(IllegalArgumentException.class, () -> logService.createReader(queueId, 5));
    logService.deleteBeforeOffset(queueId, 2);
    assertThrows(IllegalArgumentException.class, () -> logService.createReader(queueId, 1));
    writer.close();
    logService.destroy();
}
Also used : ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) LogWriter(com.alibaba.graphscope.groot.wal.LogWriter) Configs(com.alibaba.maxgraph.common.config.Configs) LogReader(com.alibaba.graphscope.groot.wal.LogReader) KafkaLogService(com.alibaba.graphscope.groot.wal.kafka.KafkaLogService) KafkaLogService(com.alibaba.graphscope.groot.wal.kafka.KafkaLogService) LogService(com.alibaba.graphscope.groot.wal.LogService) LogEntry(com.alibaba.graphscope.groot.wal.LogEntry) ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) Test(org.junit.jupiter.api.Test)

Example 2 with LogReader

use of com.alibaba.graphscope.groot.wal.LogReader in project GraphScope by alibaba.

the class IngestProcessorTest method testIngestProcessor.

@Test
void testIngestProcessor() throws IOException {
    long tailOffset = 50L;
    int queueId = 0;
    Configs configs = Configs.newBuilder().build();
    LogService mockLogService = mock(LogService.class);
    LogReader mockLogReader = mock(LogReader.class);
    when(mockLogService.createReader(queueId, tailOffset + 1)).thenReturn(mockLogReader);
    LogWriter mockLogWriter = mock(LogWriter.class);
    when(mockLogService.createWriter(queueId)).thenReturn(mockLogWriter);
    when(mockLogWriter.append(any())).thenReturn(tailOffset + 3);
    OperationBatch emptyBatch = OperationBatch.newBuilder().build();
    long readSnapshotId = 5L;
    ReadLogEntry readLogEntry1 = new ReadLogEntry(tailOffset + 1, readSnapshotId, emptyBatch);
    ReadLogEntry readLogEntry2 = new ReadLogEntry(tailOffset + 2, readSnapshotId, emptyBatch);
    when(mockLogReader.readNext()).thenReturn(readLogEntry1).thenReturn(readLogEntry2).thenReturn(null);
    BatchSender mockBatchSender = mock(BatchSender.class);
    AtomicLong ingestSnapshotId = new AtomicLong(10L);
    IngestProcessor ingestProcessor = new IngestProcessor(configs, mockLogService, mockBatchSender, queueId, ingestSnapshotId, new MetricsCollector(configs));
    ingestProcessor.setTailOffset(tailOffset);
    ingestProcessor.start();
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 1), any());
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(eq(""), eq(queueId), eq(readSnapshotId), eq(tailOffset + 2), any());
    verify(mockLogReader).close();
    String requestId = "test_ingest_processor";
    IngestCallback mockIngestCallback = mock(IngestCallback.class);
    ingestProcessor.ingestBatch(requestId, emptyBatch, mockIngestCallback);
    verify(mockBatchSender, timeout(5000L)).asyncSendWithRetry(requestId, queueId, ingestSnapshotId.get(), tailOffset + 3, emptyBatch);
    verify(mockIngestCallback, timeout(5000L)).onSuccess(ingestSnapshotId.get());
    ingestProcessor.stop();
    verify(mockLogWriter, timeout(5000L)).close();
}
Also used : MetricsCollector(com.alibaba.graphscope.groot.metrics.MetricsCollector) BatchSender(com.alibaba.graphscope.groot.ingestor.BatchSender) ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) IngestProcessor(com.alibaba.graphscope.groot.ingestor.IngestProcessor) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) LogWriter(com.alibaba.graphscope.groot.wal.LogWriter) Configs(com.alibaba.maxgraph.common.config.Configs) LogReader(com.alibaba.graphscope.groot.wal.LogReader) IngestCallback(com.alibaba.graphscope.groot.ingestor.IngestCallback) LogService(com.alibaba.graphscope.groot.wal.LogService) Test(org.junit.jupiter.api.Test)

Example 3 with LogReader

use of com.alibaba.graphscope.groot.wal.LogReader in project GraphScope by alibaba.

the class SnapshotManager method recover.

private void recover() throws IOException {
    checkMetaPath(QUERY_SNAPSHOT_INFO_PATH);
    checkMetaPath(WRITE_SNAPSHOT_ID_PATH);
    checkMetaPath(QUEUE_OFFSETS_PATH);
    byte[] querySnapshotInfoBytes = this.metaStore.read(QUERY_SNAPSHOT_INFO_PATH);
    SnapshotInfo recoveredQuerySnapshotInfo = this.objectMapper.readValue(querySnapshotInfoBytes, SnapshotInfo.class);
    byte[] writeSnapshotIdBytes = this.metaStore.read(WRITE_SNAPSHOT_ID_PATH);
    long recoveredWriteSnapshotId = this.objectMapper.readValue(writeSnapshotIdBytes, Long.class);
    if (recoveredQuerySnapshotInfo.getSnapshotId() > recoveredWriteSnapshotId) {
        throw new IllegalStateException("recovered querySnapshotInfo [" + recoveredQuerySnapshotInfo + "] > writeSnapshotId [" + recoveredWriteSnapshotId + "]");
    }
    byte[] queueOffsetsBytes = this.metaStore.read(QUEUE_OFFSETS_PATH);
    List<Long> recoveredQueueOffsets = this.objectMapper.readValue(queueOffsetsBytes, new TypeReference<List<Long>>() {
    });
    logger.info("recovered queue offsets [" + recoveredQueueOffsets + "]");
    if (recoveredQueueOffsets.size() != this.queueCount) {
        throw new IllegalStateException("recovered queueCount [" + recoveredQueueOffsets.size() + "], but expect queueCount [" + this.queueCount + "]");
    }
    for (int i = 0; i < this.queueCount; i++) {
        long recoveredOffset = recoveredQueueOffsets.get(i);
        LogReader reader = null;
        try {
            reader = logService.createReader(i, recoveredOffset + 1);
        } catch (Exception e) {
            throw new IOException("recovered queue [" + i + "] offset [" + recoveredOffset + "] is not available", e);
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
    this.querySnapshotInfo = recoveredQuerySnapshotInfo;
    this.writeSnapshotId = recoveredWriteSnapshotId;
    this.queueOffsetsRef = new AtomicReference<>(recoveredQueueOffsets);
}
Also used : IOException(java.io.IOException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LogReader(com.alibaba.graphscope.groot.wal.LogReader) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with LogReader

use of com.alibaba.graphscope.groot.wal.LogReader in project GraphScope by alibaba.

the class IngestProcessor method replayWAL.

private void replayWAL(long tailOffset) throws IOException {
    long replayFrom = tailOffset + 1;
    logger.info("replay WAL of queue#[" + this.queueId + "] from offset [" + replayFrom + "]");
    LogReader logReader = this.logService.createReader(this.queueId, replayFrom);
    ReadLogEntry readLogEntry;
    int replayCount = 0;
    while (!shouldStop && (readLogEntry = logReader.readNext()) != null) {
        long offset = readLogEntry.getOffset();
        LogEntry logEntry = readLogEntry.getLogEntry();
        long snapshotId = logEntry.getSnapshotId();
        OperationBatch operationBatch = logEntry.getOperationBatch();
        this.batchSender.asyncSendWithRetry("", this.queueId, snapshotId, offset, operationBatch);
        replayCount++;
    }
    try {
        logReader.close();
    } catch (IOException e) {
        logger.warn("close logReader failed", e);
    }
    logger.info("replayWAL finished. total replayed [" + replayCount + "] records");
}
Also used : ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) LogReader(com.alibaba.graphscope.groot.wal.LogReader) IOException(java.io.IOException) LogEntry(com.alibaba.graphscope.groot.wal.LogEntry) ReadLogEntry(com.alibaba.graphscope.groot.wal.ReadLogEntry) OperationBatch(com.alibaba.graphscope.groot.operation.OperationBatch)

Aggregations

LogReader (com.alibaba.graphscope.groot.wal.LogReader)4 OperationBatch (com.alibaba.graphscope.groot.operation.OperationBatch)3 ReadLogEntry (com.alibaba.graphscope.groot.wal.ReadLogEntry)3 LogEntry (com.alibaba.graphscope.groot.wal.LogEntry)2 LogService (com.alibaba.graphscope.groot.wal.LogService)2 LogWriter (com.alibaba.graphscope.groot.wal.LogWriter)2 Configs (com.alibaba.maxgraph.common.config.Configs)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 BatchSender (com.alibaba.graphscope.groot.ingestor.BatchSender)1 IngestCallback (com.alibaba.graphscope.groot.ingestor.IngestCallback)1 IngestProcessor (com.alibaba.graphscope.groot.ingestor.IngestProcessor)1 MetricsCollector (com.alibaba.graphscope.groot.metrics.MetricsCollector)1 KafkaLogService (com.alibaba.graphscope.groot.wal.kafka.KafkaLogService)1 MaxGraphException (com.alibaba.maxgraph.compiler.api.exception.MaxGraphException)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1