Skip to content

Commit

Permalink
chore: added processing of deleteSession into Query service
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Zorkaltsev committed May 14, 2024
1 parent d3ff782 commit bdd0836
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/e2e/query-service/query-service-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Query client', () => {
expect(session.txId).toBeDefined();

// force new attempt
if (count < 3) throw new errors.Unavailable('test'); // an fast backoff error
if (count < 3) throw new errors.Aborted('test'); // an fast backoff error

res = await session.execute({
txControl: {commitTx: true},
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('Query client', () => {
expect(session.txId).toBeDefined();

// force new attempt
if (count < 2) throw new errors.Unavailable('test'); // an fast backoff error
if (count < 2) throw new errors.Aborted('test'); // an fast backoff error

await expect(async () =>
await session.commitTransaction()
Expand Down
3 changes: 2 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export class Aborted extends YdbError {

export class Unavailable extends YdbError {
static status = StatusCode.UNAVAILABLE;
public readonly [RetryPolicySymbol] = retryPolicy(Backoff.Fast, false, true, true);
// TODO: Requires extra logic - see https://github.com/ydb-platform/ydb-go-sdk/blob/e1ba79620427a66c1564a52abe7e1ff10787d442/retry/errors_data_test.go#L197
public readonly [RetryPolicySymbol] = retryPolicy(Backoff.Fast, false, true, false);
}

export class Overloaded extends YdbError {
Expand Down
10 changes: 6 additions & 4 deletions src/query/query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {ensureContext} from "../context";
import {Logger} from "../logger/simple-logger";
import {RetryStrategy} from "../retries/retryStrategy";
import {RetryParameters} from "../retries/retryParameters";
import {RetryPolicySymbol} from "../retries/symbols";

export interface IQueryClientSettings {
database: string;
Expand Down Expand Up @@ -78,7 +79,7 @@ export class QueryClient extends EventEmitter {
session[isIdempotentDoLevelSymbol] = true;
session[isIdempotentSymbol] = opts.idempotent;
}
let error;
let error: Error;
try {
if (opts.txSettings) session[sessionTxSettingsSymbol] = opts.txSettings;
let res: T;
Expand All @@ -101,15 +102,16 @@ export class QueryClient extends EventEmitter {
}
return {result: res};
} catch (err) {
error = err;
return {err: err as Error, idempotent: session[isIdempotentSymbol]}
error = err as Error;
return {err: error, idempotent: session[isIdempotentSymbol]}
} finally {
delete session[ctxSymbol];
delete session[sessionTxSettingsSymbol];
delete session[sessionCurrentOperationSymbol];
delete session[isIdempotentDoLevelSymbol];
delete session[isIdempotentSymbol];
if (error instanceof BadSession || error instanceof SessionBusy) {
// @ts-ignore
if (error && (error as any)[RetryPolicySymbol]?.deleteSession) {
this.logger.debug('Encountered bad or busy session, re-creating the session');
session.emit(SessionEvent.SESSION_BROKEN);
} else {
Expand Down

0 comments on commit bdd0836

Please sign in to comment.