Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphql/graphql-server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
command: ["postgres", "-c", "log_statement=all"]

cockroach:
image: cockroachdb/cockroach:v21.2.9
image: cockroachdb/cockroach:v23.2.2
ports:
- "${DB_PORT_COCKROACH}:26257"
command: ["start-single-node", "--insecure"]
2 changes: 2 additions & 0 deletions graphql/graphql-server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ runProgram(async () => {
program.option('--max-response-size <nodes>', 'max response size measured in nodes', nat)
program.option('--sql-statement-timeout <ms>', 'sql statement timeout in ms', nat)
program.option('--validation-max-errors <count>', 'max validation errors', nat)
program.addOption(new Option('--isolation-level <level>', 'transaction isolation level').choices(['SERIALIZABLE', 'REPEATABLE READ', 'READ COMMITTED']))
program.option('--subscriptions', 'enable gql subscriptions')
program.option('--subscription-poll-interval <ms>', 'subscription poll interval in ms', nat, 5000)
program.option('--subscription-max-response-size <nodes>', 'max response size measured in nodes', nat)
Expand All @@ -46,6 +47,7 @@ runProgram(async () => {
validationMaxErrors?: number
tsNode?: boolean
dialect?: Dialect
isolationLevel: 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED'
}

await registerTsNodeIfRequired()
Expand Down
2 changes: 2 additions & 0 deletions graphql/graphql-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ServerOptions {
validationMaxErrors?: number
dumbCache?: DumbRedisCacheOptions | DumbInMemoryCacheOptions
dialect?: Dialect
isolationLevel?: 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED'
}


Expand Down Expand Up @@ -244,6 +245,7 @@ export class Server {
pool,
pool,
this.options.subscriptionPollInterval,
this.options.isolationLevel,
this.options.log
)
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/openreader/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
command: ["postgres", "-c", "log_statement=all"]

cockroach:
image: cockroachdb/cockroach:v21.2.9
image: cockroachdb/cockroach:v23.2.2
ports:
- "${DB_PORT_COCKROACH}:26257"
command: [
Expand Down
5 changes: 4 additions & 1 deletion graphql/openreader/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ let CTX_COUNTER = 0
export type DbType = 'postgres' | 'cockroach'


export type TransactionIsolationLevel = 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED'

export class PoolOpenreaderContext implements OpenreaderContext {
public id = (CTX_COUNTER = (CTX_COUNTER + 1) % Number.MAX_SAFE_INTEGER)
public log?: Logger
Expand All @@ -26,6 +28,7 @@ export class PoolOpenreaderContext implements OpenreaderContext {
pool: Pool,
subscriptionPool?: Pool,
private subscriptionPollInterval: number = 1000,
private isolationLevel: TransactionIsolationLevel = 'SERIALIZABLE',
log?: Logger
) {
this.log = log?.child({graphqlCtx: this.id})
Expand Down Expand Up @@ -53,7 +56,7 @@ export class PoolOpenreaderContext implements OpenreaderContext {
private async transact<T>(pool: Pool, cb: (db: Database) => Promise<T>): Promise<T> {
let client = await pool.connect()
try {
await this.query(client, 'START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY')
await this.query(client, `START TRANSACTION ISOLATION LEVEL ${this.isolationLevel} READ ONLY`)
try {
return await cb(async (sql, parameters) => {
let result = await this.query(client, sql, parameters)
Expand Down
5 changes: 4 additions & 1 deletion graphql/openreader/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ GraphQL server for postgres-compatible databases
program.option('--subscriptions', 'enable gql subscriptions')
program.option('--subscription-poll-interval <ms>', 'subscription poll interval in ms', nat, 1000)
program.option('--subscription-max-response-size <nodes>', 'max response size measured in nodes', nat)
program.addOption(new Option('--isolation-level <level>', 'transaction isolation level').choices(['SERIALIZABLE', 'REPEATABLE READ', 'READ COMMITTED']))

let opts = program.parse().opts() as {
schema: string
Expand All @@ -47,6 +48,7 @@ GraphQL server for postgres-compatible databases
subscriptions?: boolean
subscriptionPollInterval: number
subscriptionMaxResponseSize?: number
isolationLevel: 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED'
}

let model = loadModel(opts.schema)
Expand All @@ -68,7 +70,8 @@ GraphQL server for postgres-compatible databases
subscriptions: opts.subscriptions,
subscriptionPollInterval: opts.subscriptionPollInterval,
subscriptionMaxResponseNodes: opts.subscriptionMaxResponseSize,
validationMaxErrors: opts.validationMaxErrors
validationMaxErrors: opts.validationMaxErrors,
isolationLevel: opts.isolationLevel
})

LOG.info(`listening on port ${server.port}`)
Expand Down
4 changes: 4 additions & 0 deletions graphql/openreader/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ServerOptions {
subscriptionMaxResponseNodes?: number
validationMaxErrors?: number
cache?: KeyValueCache
isolationLevel?: 'SERIALIZABLE' | 'REPEATABLE READ' | 'READ COMMITTED'
}

export async function serve(options: ServerOptions): Promise<ListeningServer> {
Expand All @@ -54,12 +55,15 @@ export async function serve(options: ServerOptions): Promise<ListeningServer> {
let schemaBuilder = await getSchemaBuilder(options)
let schema = schemaBuilder.build()

let isolationLevel = options.isolationLevel ?? 'SERIALIZABLE'

let context = () => {
let openreader: OpenreaderContext = new PoolOpenreaderContext(
dbType,
connection,
subscriptionConnection,
subscriptionPollInterval,
isolationLevel,
log
)

Expand Down