Skip to content

Commit 0904feb

Browse files
committed
allow to read special logs from previous epoch
1 parent eb0168c commit 0904feb

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

RESTAPI/bobAPI.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,30 @@ std::string bobGetLog(uint16_t epoch, int64_t start, int64_t end)
182182
for (int64_t id = start; id <= end; ++id) {
183183
LogEvent log;
184184
if (db_try_get_log(epoch, static_cast<uint64_t>(id), log)) {
185-
if (log.getTick() != gInitialTick)
185+
if (!db_try_get_log_ranges(log.getTick(), lr))
186+
{
187+
Json::Value err(Json::objectValue);
188+
err["ok"] = false;
189+
err["error"] = "Missing log range " + std::to_string(log.getTick())
190+
+ ". Cannot process logging events";
191+
err["epoch"] = epoch;
192+
err["logId"] = Json::UInt64(static_cast<uint64_t>(id));
193+
Json::StreamWriterBuilder wb;
194+
wb["indentation"] = "";
195+
std::string js = Json::writeString(wb, err);
196+
if (!first) result.push_back(',');
197+
result += js;
198+
result.push_back(']');
199+
return result;
200+
}
201+
202+
logTxOrderIndex = 0;
203+
logTxOrder = lr.sort();
204+
// scan to find the first cursor
205+
logTxOrderIndex = lr.scanTxId(logTxOrder, 0, log.getLogId());
206+
int txIndex = logTxOrder[logTxOrderIndex];
207+
208+
if (log.getTick() != gInitialTick && txIndex < NUMBER_OF_TRANSACTIONS_PER_TICK)
186209
{
187210
db_try_get_tick_data(log.getTick(), td);
188211
if (td.epoch == 0)
@@ -222,17 +245,13 @@ std::string bobGetLog(uint16_t epoch, int64_t start, int64_t end)
222245
}
223246
}
224247
}
225-
db_try_get_log_ranges(log.getTick(), lr);
226-
logTxOrderIndex = 0;
227-
logTxOrder = lr.sort();
228-
// scan to find the first cursor
229-
logTxOrderIndex = lr.scanTxId(logTxOrder, 0, log.getLogId());
248+
230249
if (logTxOrderIndex == -1)
231250
{
232251
result.push_back(']');
233252
return result;
234253
}
235-
int txIndex = logTxOrder[logTxOrderIndex];
254+
txIndex = logTxOrder[logTxOrderIndex];
236255
auto s = lr.fromLogId[txIndex];
237256
auto e = s + lr.length[txIndex] - 1;
238257
if (id > e) // processed all, move the cursor to next tx

0 commit comments

Comments
 (0)