Skip to content

testkit: Implements ForcedRoutingTableUpdate #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2021
Merged
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
34 changes: 31 additions & 3 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,45 @@ export function GetRoutingTable (context, { driverId, database }, wire) {
driver &&
driver._getOrCreateConnectionProvider() &&
driver._getOrCreateConnectionProvider()._routingTableRegistry &&
driver._getOrCreateConnectionProvider()._routingTableRegistry.get(database)
driver._getOrCreateConnectionProvider()._routingTableRegistry.get(database, () => {
return {
database,
ttl: 0,
readers: [],
writers: [],
routers: []
}
})

if (routingTable) {
wire.writeResponse('RoutingTable', {
database: routingTable.database,
ttl: routingTable.ttl,
ttl: Number(routingTable.ttl),
readers: routingTable.readers.map(serverAddressToString),
writers: routingTable.writers.map(serverAddressToString),
routers: routingTable.routers.map(serverAddressToString)
})
} else {
wire.writeError('Could not find routing table')
wire.writeError('Driver does not support routing')
}
}

export function ForcedRoutingTableUpdate (context, { driverId, database, bookmarks }, wire) {
const driver = context.getDriver(driverId)
const provider = driver._getOrCreateConnectionProvider()

if (provider._freshRoutingTable) {
// Removing database from the routing table registry
Copy link
Member

@robsdedude robsdedude Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take the PR as is. But I'll suggest to extend that comment with a few words explaining why you decided to delete the RT and go through _freshRoutingTable instead of just calling _refreshRoutingTable which might seem like the better solution (but isn't as you commented).

provider._routingTableRegistry._remove(database)
provider._freshRoutingTable ({
accessMode: 'READ',
database,
bookmark: bookmarks,
onDatabaseNameResolved: () => {}
})
.then(() => wire.writeResponse("Driver", { "id": driverId }))
.catch(error => wire.writeError(error))
} else {
wire.writeError('Driver does not support routing')
}
}