Skip to content

Commit

Permalink
feat: add alter table async mode handling
Browse files Browse the repository at this point in the history
Backend does not return status if request made in async mode.
So, suppress error `MissingStatus` in case of async mode in alterTable
  • Loading branch information
zeruk committed Feb 9, 2023
1 parent d9b7fb4 commit 9c18405
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import ExecuteScanQueryPartialResult = Ydb.Table.ExecuteScanQueryPartialResult;
import IKeyRange = Ydb.Table.IKeyRange;
import TypedValue = Ydb.TypedValue;
import BulkUpsertResult = Ydb.Table.BulkUpsertResult;
import OperationMode = Ydb.Operations.OperationParams.OperationMode;

interface PartialResponse<T> {
status?: (Ydb.StatusIds.StatusCode|null);
Expand Down Expand Up @@ -100,19 +101,19 @@ interface IQueryParams {
}

export class OperationParams implements Ydb.Operations.IOperationParams {
operationMode?: Ydb.Operations.OperationParams.OperationMode;
operationMode?: OperationMode;
operationTimeout?: google.protobuf.IDuration;
cancelAfter?: google.protobuf.IDuration;
labels?: { [k: string]: string };
reportCostInfo?: Ydb.FeatureFlag.Status;

withSyncMode() {
this.operationMode = Ydb.Operations.OperationParams.OperationMode.SYNC;
this.operationMode = OperationMode.SYNC;
return this;
}

withAsyncMode() {
this.operationMode = Ydb.Operations.OperationParams.OperationMode.ASYNC;
this.operationMode = OperationMode.ASYNC;
return this;
}

Expand Down Expand Up @@ -377,7 +378,11 @@ export class Session extends EventEmitter implements ICreateSessionResult {

@retryable()
@pessimizable
public async alterTable(tablePath: string, description: AlterTableDescription, settings?: AlterTableSettings): Promise<void> {
public async alterTable(
tablePath: string,
description: AlterTableDescription,
settings?: AlterTableSettings
): Promise<void> {
const request: Ydb.Table.IAlterTableRequest = {
...description,
sessionId: this.sessionId,
Expand All @@ -386,8 +391,15 @@ export class Session extends EventEmitter implements ICreateSessionResult {
if (settings) {
request.operationParams = settings.operationParams;
}

// !! does not returns response if async operation mode
const response = await this.api.alterTable(request);
ensureOperationSucceeded(this.processResponseMetadata(request, response));
try {
ensureOperationSucceeded(this.processResponseMetadata(request, response));
} catch (error) {
if (request.operationParams?.operationMode !== OperationMode.SYNC && error instanceof MissingStatus) {
} else throw error;
}
}

/*
Expand Down

0 comments on commit 9c18405

Please sign in to comment.