tweak the metadata line handler to handle an edge case in trim history
This commit is contained in:
@@ -211,12 +211,14 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||||||
line: JSON.stringify(line),
|
line: JSON.stringify(line),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the case above is special, everything else should increment the index
|
||||||
|
var index = ref.index++;
|
||||||
if (typeof(line) === 'undefined') { return; }
|
if (typeof(line) === 'undefined') { return; }
|
||||||
|
|
||||||
if (Array.isArray(line)) {
|
if (Array.isArray(line)) {
|
||||||
try {
|
try {
|
||||||
handleCommand(ref.meta, line);
|
handleCommand(ref.meta, line);
|
||||||
ref.index++;
|
|
||||||
} catch (err2) {
|
} catch (err2) {
|
||||||
errorHandler("METADATA_COMMAND_ERR", {
|
errorHandler("METADATA_COMMAND_ERR", {
|
||||||
error: err2.stack,
|
error: err2.stack,
|
||||||
@@ -226,8 +228,15 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref.index === 0 && typeof(line) === 'object') {
|
// the first line of a channel is processed before the dedicated metadata log.
|
||||||
ref.index++;
|
// it can contain a map, in which case it should be used as the initial state.
|
||||||
|
// it's possible that a trim-history command was interrupted, in which case
|
||||||
|
// this first message might exist in parallel with the more recent metadata log
|
||||||
|
// which will contain the computed state of the previous metadata log
|
||||||
|
// which has since been archived.
|
||||||
|
// Thus, accept both the first and second lines you process as valid initial state
|
||||||
|
// preferring the second if it exists
|
||||||
|
if (index < 2 && line typeof(line) === 'object') {
|
||||||
// special case!
|
// special case!
|
||||||
ref.meta = line;
|
ref.meta = line;
|
||||||
return;
|
return;
|
||||||
@@ -235,7 +244,7 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||||||
|
|
||||||
errorHandler("METADATA_HANDLER_WEIRDLINE", {
|
errorHandler("METADATA_HANDLER_WEIRDLINE", {
|
||||||
line: line,
|
line: line,
|
||||||
index: ref.index++,
|
index: index,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user