Skip to content

Commit

Permalink
Add Logs for SessionHelper (#12574)
Browse files Browse the repository at this point in the history
We have one session existing in the two clusters at the same time, we
don't have enough telemetry to debug this case. When a client would like
to open an existing session, it might doesn't follow the session
stickiness time, and directly join from the wrong cluster. For example,
one session just terminated in cluster A. After a few minutes, it
violate the session stickiness time (3 hours) and was open in cluster B.
We would like to add more telemetry to debug this scenario. 

![Screen Shot 2022-10-18 at 7 23 20
PM](https://user-images.githubusercontent.com/66701969/196582570-a6e0cecd-39b8-42bb-baf9-9465124113c0.png)
  • Loading branch information
tianzhu007 authored Oct 25, 2022
1 parent 2b6742e commit b7bab5c
Showing 1 changed file with 28 additions and 5 deletions.
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,28 @@ 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,
isSessionSticky,
sessionHasLocation,
// 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 +144,10 @@ async function updateExistingSession(
session: updatedSession,
},
null);
Lumberjack.info(
`The Session ${JSON.stringify(updatedSession)} was updated into the document collection`,
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 Expand Up @@ -176,6 +195,10 @@ export async function getSession(
}
// Session can be undefined for documents that existed before the concept of service sessions.
const existingSession: ISession | undefined = document.session;
Lumberjack.info(
`The existingSession in getSession: ${JSON.stringify(existingSession)}`,
lumberjackProperties,
);

if (!existingSession) {
// Create a new session for the document and persist to DB.
Expand Down

0 comments on commit b7bab5c

Please sign in to comment.