-
Notifications
You must be signed in to change notification settings - Fork 21
Implement and test configurable transaction timeouts #197
Changes from all commits
213fae6
5caed4a
1ad353b
5edba1b
929d7f8
892b74a
a93032e
7eed859
e77b84a
4de4eb9
ec036f2
b1fc1ae
7ab502d
adba8df
5b7781e
0a66f3e
c074d17
f14db6e
a13bfc6
a35d1cd
ae3c735
6c808c5
2e16729
11f67fd
debad9b
513ca53
1935793
70b1a52
3f31ea6
9c5ac16
e05c95a
3efdfa9
dbdff45
2e77538
2291c2d
64305c9
c994ed9
6000f1e
7937d34
81b6d02
d0f135f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ | |
* under the License. | ||
*/ | ||
|
||
import { Options } from "typedb-protocol/common/options_pb"; | ||
import { ErrorMessage } from "../../common/errors/ErrorMessage"; | ||
import { TypeDBClientError } from "../../common/errors/TypeDBClientError"; | ||
import {Options} from "typedb-protocol/common/options_pb"; | ||
import {ErrorMessage} from "../../common/errors/ErrorMessage"; | ||
import {TypeDBClientError} from "../../common/errors/TypeDBClientError"; | ||
import NEGATIVE_VALUE_NOT_ALLOWED = ErrorMessage.Client.NEGATIVE_VALUE_NOT_ALLOWED; | ||
|
||
namespace Opts { | ||
|
@@ -33,6 +33,7 @@ namespace Opts { | |
prefetchSize?: number; | ||
prefetch?: boolean; | ||
sessionIdleTimeoutMillis?: number; | ||
transactionTimeoutMillis?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new transaction option: millis before timeout |
||
schemaLockAcquireTimeoutMillis?: number; | ||
} | ||
|
||
|
@@ -50,6 +51,7 @@ namespace Opts { | |
if (options.prefetchSize != null) optionsProto.setPrefetchSize(options.prefetchSize); | ||
if (options.prefetch != null) optionsProto.setPrefetch(options.prefetch); | ||
if (options.sessionIdleTimeoutMillis != null) optionsProto.setSessionIdleTimeoutMillis(options.sessionIdleTimeoutMillis); | ||
if (options.transactionTimeoutMillis != null) optionsProto.setTransactionTimeoutMillis(options.transactionTimeoutMillis); | ||
if (options.schemaLockAcquireTimeoutMillis != null) optionsProto.setSchemaLockAcquireTimeoutMillis(options.schemaLockAcquireTimeoutMillis); | ||
if (options.isCluster()) { | ||
const clusterOptions = options as Opts.Cluster; | ||
|
@@ -69,6 +71,7 @@ export class TypeDBOptions implements Opts.Core { | |
private _prefetchSize: number; | ||
private _prefetch: boolean; | ||
private _sessionIdleTimeoutMillis: number; | ||
private _transactionTimeoutMillis: number; | ||
private _schemaLockAcquireTimeoutMillis: number; | ||
|
||
constructor(obj: { [K in keyof Opts.Core]: Opts.Core[K] } = {}) { | ||
|
@@ -138,11 +141,22 @@ export class TypeDBOptions implements Opts.Core { | |
return this._sessionIdleTimeoutMillis; | ||
} | ||
|
||
set sessionIdleTimeoutMillis(value: number) { | ||
if (value < 1) { | ||
throw new TypeDBClientError(NEGATIVE_VALUE_NOT_ALLOWED.message(value)); | ||
set sessionIdleTimeoutMillis(millis: number) { | ||
if (millis < 1) { | ||
throw new TypeDBClientError(NEGATIVE_VALUE_NOT_ALLOWED.message(millis)); | ||
} | ||
this._sessionIdleTimeoutMillis = millis; | ||
} | ||
|
||
get transactionTimeoutMillis() { | ||
return this._transactionTimeoutMillis; | ||
} | ||
|
||
set transactionTimeoutMillis(millis: number) { | ||
if (millis < 1) { | ||
throw new TypeDBClientError(NEGATIVE_VALUE_NOT_ALLOWED.message(millis)); | ||
} | ||
this._sessionIdleTimeoutMillis = value; | ||
this._transactionTimeoutMillis = millis; | ||
Comment on lines
+151
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setter/getter for transaction timeouts |
||
} | ||
|
||
get schemaLockAcquireTimeoutMillis() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,22 +19,25 @@ | |
* under the License. | ||
*/ | ||
|
||
import { Transaction } from "typedb-protocol/common/transaction_pb"; | ||
import { ConceptManager } from "../api/concept/ConceptManager"; | ||
import { TypeDBOptions } from "../api/connection/TypeDBOptions"; | ||
import { TransactionType, TypeDBTransaction } from "../api/connection/TypeDBTransaction"; | ||
import { LogicManager } from "../api/logic/LogicManager"; | ||
import { QueryManager } from "../api/query/QueryManager"; | ||
import { ErrorMessage } from "../common/errors/ErrorMessage"; | ||
import { TypeDBClientError } from "../common/errors/TypeDBClientError"; | ||
import { RequestBuilder } from "../common/rpc/RequestBuilder"; | ||
import { Stream } from "../common/util/Stream"; | ||
import { ConceptManagerImpl } from "../concept/ConceptManagerImpl"; | ||
import { LogicManagerImpl } from "../logic/LogicManagerImpl"; | ||
import { QueryManagerImpl } from "../query/QueryManagerImpl"; | ||
import { BidirectionalStream } from "../stream/BidirectionalStream"; | ||
import { TypeDBSessionImpl } from "./TypeDBSessionImpl"; | ||
import {Transaction} from "typedb-protocol/common/transaction_pb"; | ||
import {ConceptManager} from "../api/concept/ConceptManager"; | ||
import {TypeDBOptions} from "../api/connection/TypeDBOptions"; | ||
import {TransactionType, TypeDBTransaction} from "../api/connection/TypeDBTransaction"; | ||
import {LogicManager} from "../api/logic/LogicManager"; | ||
import {QueryManager} from "../api/query/QueryManager"; | ||
import {ErrorMessage} from "../common/errors/ErrorMessage"; | ||
import {TypeDBClientError} from "../common/errors/TypeDBClientError"; | ||
import {RequestBuilder} from "../common/rpc/RequestBuilder"; | ||
import {Stream} from "../common/util/Stream"; | ||
import {ConceptManagerImpl} from "../concept/ConceptManagerImpl"; | ||
import {LogicManagerImpl} from "../logic/LogicManagerImpl"; | ||
import {QueryManagerImpl} from "../query/QueryManagerImpl"; | ||
import {BidirectionalStream} from "../stream/BidirectionalStream"; | ||
import {TypeDBSessionImpl} from "./TypeDBSessionImpl"; | ||
import assert = require("assert"); | ||
Comment on lines
+22
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto format.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've never used Unlike in Java, there is no clean way to turn off assertions in NodeJS. (Methods typically used include hot module replacement - literally stripping the statements out of the source code before running it - and modifying the I think we're better off replacing it with
flyingsilverfin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import TRANSACTION_CLOSED = ErrorMessage.Client.TRANSACTION_CLOSED; | ||
import TRANSACTION_CLOSED_WITH_ERRORS = ErrorMessage.Client.TRANSACTION_CLOSED_WITH_ERRORS; | ||
import ILLEGAL_STATE = ErrorMessage.Internal.ILLEGAL_STATE; | ||
|
||
export class TypeDBTransactionImpl implements TypeDBTransaction.Extended { | ||
private readonly _session: TypeDBSessionImpl; | ||
|
@@ -105,13 +108,20 @@ export class TypeDBTransactionImpl implements TypeDBTransaction.Extended { | |
} | ||
|
||
public async rpcExecute(request: Transaction.Req, batch?: boolean): Promise<Transaction.Res> { | ||
if (!this.isOpen()) throw new TypeDBClientError(TRANSACTION_CLOSED); | ||
if (!this.isOpen()) this.throwTransactionClosed() | ||
const useBatch = batch !== false; | ||
return this._bidirectionalStream.single(request, useBatch); | ||
} | ||
|
||
public rpcStream(request: Transaction.Req): Stream<Transaction.ResPart> { | ||
if (!this.isOpen()) throw new TypeDBClientError(TRANSACTION_CLOSED); | ||
if (!this.isOpen()) this.throwTransactionClosed(); | ||
return this._bidirectionalStream.stream(request); | ||
} | ||
|
||
private throwTransactionClosed(): void { | ||
if (this.isOpen()) throw new TypeDBClientError(ILLEGAL_STATE); | ||
const errors = this._bidirectionalStream.getErrors(); | ||
if (errors.length == 0) throw new TypeDBClientError(TRANSACTION_CLOSED); | ||
else throw new TypeDBClientError(TRANSACTION_CLOSED_WITH_ERRORS.message(errors)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following other clients' we extract the
wait
steps into their ownUtilSteps
file