Skip to content

Commit 65acc23

Browse files
committed
fix: remove begin call for non retriable errors
1 parent 4d7b0aa commit 65acc23

File tree

5 files changed

+4
-151
lines changed

5 files changed

+4
-151
lines changed

observability-test/database.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ describe('Database', () => {
16871687
'Unexpected span status message'
16881688
);
16891689

1690-
const expectedEventNames = ['Using Session'];
1690+
const expectedEventNames = ['Using Session', 'exception'];
16911691
assert.deepStrictEqual(
16921692
actualEventNames,
16931693
expectedEventNames,

observability-test/spanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe('EndToEnd', () => {
473473
database.formattedName_
474474
);
475475
await database.runTransactionAsync(async transaction => {
476-
const [rows] = await transaction!.run('SELECT 1');
476+
await transaction!.run('SELECT 1');
477477
});
478478

479479
traceExporter.forceFlush();

src/database.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3395,7 +3395,7 @@ class Database extends common.GrpcServiceObject {
33953395
try {
33963396
return await runner.run();
33973397
} catch (e) {
3398-
setSpanError(span, e as Error);
3398+
setSpanErrorAndException(span, e as Error);
33993399
throw e;
34003400
} finally {
34013401
span.end();

src/transaction.ts

-30
Original file line numberDiff line numberDiff line change
@@ -743,21 +743,6 @@ export class Snapshot extends EventEmitter {
743743
this._update(response.metadata!.transaction);
744744
}
745745
})
746-
.on('error', err => {
747-
const isServiceError =
748-
err && typeof err === 'object' && 'code' in err;
749-
if (
750-
!this.id &&
751-
this._useInRunner &&
752-
!(
753-
isServiceError &&
754-
(err as grpc.ServiceError).code === grpc.status.ABORTED
755-
)
756-
) {
757-
this.begin();
758-
}
759-
setSpanError(span, err);
760-
})
761746
.on('end', err => {
762747
if (err) {
763748
setSpanError(span, err);
@@ -1318,21 +1303,6 @@ export class Snapshot extends EventEmitter {
13181303
this._update(response.metadata!.transaction);
13191304
}
13201305
})
1321-
.on('error', err => {
1322-
setSpanError(span, err as Error);
1323-
const isServiceError =
1324-
err && typeof err === 'object' && 'code' in err;
1325-
if (
1326-
!this.id &&
1327-
this._useInRunner &&
1328-
!(
1329-
isServiceError &&
1330-
(err as grpc.ServiceError).code === grpc.status.ABORTED
1331-
)
1332-
) {
1333-
this.begin();
1334-
}
1335-
})
13361306
.on('end', err => {
13371307
if (err) {
13381308
setSpanError(span, err as Error);

test/spanner.ts

+1-118
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,8 @@ describe('Spanner with mock server', () => {
452452
request.requestOptions!.transactionTag,
453453
'transaction-tag'
454454
);
455-
const beginTxnRequest = spannerMock.getRequests().find(val => {
456-
return (val as v1.BeginTransactionRequest).options?.readWrite;
457-
}) as v1.BeginTransactionRequest;
458455
assert.strictEqual(
459-
beginTxnRequest.options?.readWrite!.readLockMode,
456+
request.transaction?.begin?.readWrite?.readLockMode,
460457
'OPTIMISTIC'
461458
);
462459
});
@@ -3758,120 +3755,6 @@ describe('Spanner with mock server', () => {
37583755
);
37593756
});
37603757

3761-
it('should use beginTransaction on retry for unknown reason', async () => {
3762-
const database = newTestDatabase();
3763-
await database.runTransactionAsync(async tx => {
3764-
try {
3765-
await tx.runUpdate(invalidSql);
3766-
assert.fail('missing expected error');
3767-
} catch (e) {
3768-
assert.strictEqual(
3769-
(e as ServiceError).message,
3770-
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
3771-
);
3772-
}
3773-
await tx.run(selectSql);
3774-
await tx.commit();
3775-
});
3776-
await database.close();
3777-
3778-
const beginTxnRequest = spannerMock
3779-
.getRequests()
3780-
.filter(val => (val as v1.BeginTransactionRequest).options?.readWrite)
3781-
.map(req => req as v1.BeginTransactionRequest);
3782-
assert.deepStrictEqual(beginTxnRequest.length, 1);
3783-
});
3784-
3785-
it('should use beginTransaction on retry for unknown reason with excludeTxnFromChangeStreams', async () => {
3786-
const database = newTestDatabase();
3787-
await database.runTransactionAsync(
3788-
{
3789-
excludeTxnFromChangeStreams: true,
3790-
},
3791-
async tx => {
3792-
try {
3793-
await tx.runUpdate(invalidSql);
3794-
assert.fail('missing expected error');
3795-
} catch (e) {
3796-
assert.strictEqual(
3797-
(e as ServiceError).message,
3798-
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
3799-
);
3800-
}
3801-
await tx.run(selectSql);
3802-
await tx.commit();
3803-
}
3804-
);
3805-
await database.close();
3806-
3807-
const beginTxnRequest = spannerMock
3808-
.getRequests()
3809-
.filter(val => (val as v1.BeginTransactionRequest).options?.readWrite)
3810-
.map(req => req as v1.BeginTransactionRequest);
3811-
assert.deepStrictEqual(beginTxnRequest.length, 1);
3812-
assert.strictEqual(
3813-
beginTxnRequest[0].options?.excludeTxnFromChangeStreams,
3814-
true
3815-
);
3816-
});
3817-
3818-
it('should use beginTransaction for streaming on retry for unknown reason', async () => {
3819-
const database = newTestDatabase();
3820-
await database.runTransactionAsync(async tx => {
3821-
try {
3822-
await getRowCountFromStreamingSql(tx!, {sql: invalidSql});
3823-
assert.fail('missing expected error');
3824-
} catch (e) {
3825-
assert.strictEqual(
3826-
(e as ServiceError).message,
3827-
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
3828-
);
3829-
}
3830-
await tx.run(selectSql);
3831-
await tx.commit();
3832-
});
3833-
await database.close();
3834-
3835-
const beginTxnRequest = spannerMock
3836-
.getRequests()
3837-
.filter(val => (val as v1.BeginTransactionRequest).options?.readWrite)
3838-
.map(req => req as v1.BeginTransactionRequest);
3839-
assert.deepStrictEqual(beginTxnRequest.length, 1);
3840-
});
3841-
3842-
it('should use beginTransaction for streaming on retry for unknown reason with excludeTxnFromChangeStreams', async () => {
3843-
const database = newTestDatabase();
3844-
await database.runTransactionAsync(
3845-
{
3846-
excludeTxnFromChangeStreams: true,
3847-
},
3848-
async tx => {
3849-
try {
3850-
await getRowCountFromStreamingSql(tx!, {sql: invalidSql});
3851-
assert.fail('missing expected error');
3852-
} catch (e) {
3853-
assert.strictEqual(
3854-
(e as ServiceError).message,
3855-
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
3856-
);
3857-
}
3858-
await tx.run(selectSql);
3859-
await tx.commit();
3860-
}
3861-
);
3862-
await database.close();
3863-
3864-
const beginTxnRequest = spannerMock
3865-
.getRequests()
3866-
.filter(val => (val as v1.BeginTransactionRequest).options?.readWrite)
3867-
.map(req => req as v1.BeginTransactionRequest);
3868-
assert.deepStrictEqual(beginTxnRequest.length, 1);
3869-
assert.strictEqual(
3870-
beginTxnRequest[0].options?.excludeTxnFromChangeStreams,
3871-
true
3872-
);
3873-
});
3874-
38753758
it('should fail if beginTransaction fails', async () => {
38763759
const database = newTestDatabase();
38773760
const err = {

0 commit comments

Comments
 (0)