|
|
@ -118,6 +118,7 @@ const computeIndex = function (data, cb) {
|
|
|
|
const CB = Util.once(cb);
|
|
|
|
const CB = Util.once(cb);
|
|
|
|
|
|
|
|
|
|
|
|
const offsetByHash = {};
|
|
|
|
const offsetByHash = {};
|
|
|
|
|
|
|
|
let offsetCount = 0;
|
|
|
|
let size = 0;
|
|
|
|
let size = 0;
|
|
|
|
nThen(function (w) {
|
|
|
|
nThen(function (w) {
|
|
|
|
// iterate over all messages in the channel log
|
|
|
|
// iterate over all messages in the channel log
|
|
|
@ -151,6 +152,8 @@ const computeIndex = function (data, cb) {
|
|
|
|
// so clear the buffer every time you see a new one
|
|
|
|
// so clear the buffer every time you see a new one
|
|
|
|
messageBuf = [];
|
|
|
|
messageBuf = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (messageBuf.length > 100 && cpIndex.length === 0) {
|
|
|
|
|
|
|
|
messageBuf = messageBuf.slice(0, 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if it's not metadata or a checkpoint then it should be a regular message
|
|
|
|
// if it's not metadata or a checkpoint then it should be a regular message
|
|
|
|
// store it in the buffer
|
|
|
|
// store it in the buffer
|
|
|
@ -163,6 +166,7 @@ const computeIndex = function (data, cb) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// once indexing is complete you should have a buffer of messages since the latest checkpoint
|
|
|
|
// once indexing is complete you should have a buffer of messages since the latest checkpoint
|
|
|
|
|
|
|
|
// or the 50-100 latest messages if the channel is of a type without checkpoints.
|
|
|
|
// map the 'hash' of each message to its byte offset in the log, to be used for reconnecting clients
|
|
|
|
// map the 'hash' of each message to its byte offset in the log, to be used for reconnecting clients
|
|
|
|
messageBuf.forEach((msgObj) => {
|
|
|
|
messageBuf.forEach((msgObj) => {
|
|
|
|
const msg = HK.tryParse(Env, msgObj.buff.toString('utf8'));
|
|
|
|
const msg = HK.tryParse(Env, msgObj.buff.toString('utf8'));
|
|
|
@ -171,6 +175,7 @@ const computeIndex = function (data, cb) {
|
|
|
|
// msgObj.offset is API guaranteed by our storage module
|
|
|
|
// msgObj.offset is API guaranteed by our storage module
|
|
|
|
// it should always be a valid positive integer
|
|
|
|
// it should always be a valid positive integer
|
|
|
|
offsetByHash[HK.getHash(msg[4])] = msgObj.offset;
|
|
|
|
offsetByHash[HK.getHash(msg[4])] = msgObj.offset;
|
|
|
|
|
|
|
|
offsetCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// There is a trailing \n at the end of the file
|
|
|
|
// There is a trailing \n at the end of the file
|
|
|
|
size = msgObj.offset + msgObj.buff.length + 1;
|
|
|
|
size = msgObj.offset + msgObj.buff.length + 1;
|
|
|
@ -182,6 +187,7 @@ const computeIndex = function (data, cb) {
|
|
|
|
// Only keep the checkpoints included in the last 100 messages
|
|
|
|
// Only keep the checkpoints included in the last 100 messages
|
|
|
|
cpIndex: HK.sliceCpIndex(cpIndex, i),
|
|
|
|
cpIndex: HK.sliceCpIndex(cpIndex, i),
|
|
|
|
offsetByHash: offsetByHash,
|
|
|
|
offsetByHash: offsetByHash,
|
|
|
|
|
|
|
|
offsets: offsetCount,
|
|
|
|
size: size,
|
|
|
|
size: size,
|
|
|
|
//metadata: metadata,
|
|
|
|
//metadata: metadata,
|
|
|
|
line: i
|
|
|
|
line: i
|
|
|
|