Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logs for SessionHelper #12574

Merged
merged 7 commits into from
Oct 25, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ async function updateExistingSession(
// that ops are backed up to a global location before a session is allowed to move.
// Otherwise, a moved session could end up without access to ops that still only exist in a location's
// non-global storage.
const sessionStickyCalculationTimestamp = Date.now();
const isSessionSticky = document.lastAccessTime !== undefined
? Date.now() - document.lastAccessTime < sessionStickinessDurationMs
? sessionStickyCalculationTimestamp - document.lastAccessTime < sessionStickinessDurationMs
: false; // If no session end has been recorded, allow session to move.
// Allow session stickiness to be overridden by manually deleting a session's orderer/historian urls.
const sessionHasLocation: boolean =
!!existingSession.ordererUrl && !!existingSession.historianUrl && !!existingSession.deltaStreamUrl;
Lumberjack.info("Calculated isSessionSticky and sessionHasLocation", {
...lumberjackProperties,
isSessionSticky,
sessionHasLocation,
documentLastAccessTime: document.lastAccessTime,
sessionStickyCalculationTimestamp,
sessionStickinessDurationMs,
});
if (!isSessionSticky || !sessionHasLocation) {
// Allow session location to be moved.
if (
Expand All @@ -89,22 +98,26 @@ async function updateExistingSession(
) {
// Previous session was in a different location. Move to current location.
// Reset logOffset, ordererUrl, and historianUrl when moving session location.
Lumberjack.info(
`Reset logOffset, ordererUrl, and historianUrl when switching cluster.`,
lumberjackProperties,
);
Lumberjack.info("Moving session", {
...lumberjackProperties,
tianzhu007 marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line max-len
oldSessionLocation: { ordererUrl: existingSession.ordererUrl, historianUrl: existingSession.historianUrl, deltaStreamUrl: existingSession.deltaStreamUrl },
newSessionLocation: { ordererUrl, historianUrl, deltaStreamUrl },
});
updatedOrdererUrl = ordererUrl;
updatedHistorianUrl = historianUrl;
updatedDeltaStreamUrl = deltaStreamUrl;
if (document.deli !== "") {
const deli = JSON.parse(document.deli);
deli.logOffset = -1;
updatedDeli = JSON.stringify(deli);
Lumberjack.info(`Reset deli logOffset as -1`, lumberjackProperties);
}
if (document.scribe !== "") {
const scribe = JSON.parse(document.scribe);
scribe.logOffset = -1;
updatedScribe = JSON.stringify(scribe);
Lumberjack.info(`Reset scribe logOffset as -1`, lumberjackProperties);
}
}
}
Expand All @@ -129,6 +142,10 @@ async function updateExistingSession(
session: updatedSession,
},
null);
Lumberjack.info(
`The Session ${JSON.stringify(updatedSession)} was updated into the document collection`,
hedasilv marked this conversation as resolved.
Show resolved Hide resolved
lumberjackProperties,
);
} catch (error) {
Lumberjack.error("Error persisting update to existing document session", lumberjackProperties, error);
throw new NetworkError(500, "Failed to persist update to document session");
Expand Down