Skip to content

Commit e1de6b4

Browse files
committed
Treat one router as valid in routing table
Previously driver considered routing table with single router to be stale and had to perform rediscovery before read/write transaction. Requirement to have more than 1 router is quite strict and can easily be violated by partially unavailable clusters. Additional rediscoveries in such cases add more load on the available core server. This commit makes driver tread routing table with single router as not stale, given that other non-staleness requirements are satisfied as well.
1 parent 4dc299d commit e1de6b4

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

src/v1/internal/routing-table.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import {int} from "../integer";
20-
import RoundRobinArray from "./round-robin-array";
19+
import {int} from '../integer';
20+
import RoundRobinArray from './round-robin-array';
2121

2222
const MIN_ROUTERS = 1;
2323

@@ -55,7 +55,7 @@ export default class RoutingTable {
5555

5656
isStale() {
5757
return this.expirationTime.lessThan(Date.now()) ||
58-
this.routers.size() <= MIN_ROUTERS ||
58+
this.routers.size() < MIN_ROUTERS ||
5959
this.readers.isEmpty() ||
6060
this.writers.isEmpty();
6161
}

test/internal/routing-table.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import RoutingTable from "../../src/v1/internal/routing-table";
20-
import RoundRobinArray from "../../src/v1/internal/round-robin-array";
21-
import {int} from "../../src/v1/integer";
19+
import RoutingTable from '../../src/v1/internal/routing-table';
20+
import RoundRobinArray from '../../src/v1/internal/round-robin-array';
21+
import {int} from '../../src/v1/integer';
2222

2323
describe('routing-table', () => {
2424

@@ -32,9 +32,9 @@ describe('routing-table', () => {
3232
expect(table.isStale()).toBeTruthy();
3333
});
3434

35-
it('should be stale when has single router', () => {
35+
it('should not be stale when has single router', () => {
3636
const table = createTable([1], [2, 3], [4, 5], notExpired());
37-
expect(table.isStale()).toBeTruthy();
37+
expect(table.isStale()).toBeFalsy();
3838
});
3939

4040
it('should be stale when no readers', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
!: AUTO PULL_ALL
4+
5+
C: RUN "CALL dbms.cluster.routing.getServers" {}
6+
PULL_ALL
7+
S: SUCCESS {"fields": ["ttl", "servers"]}
8+
RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001","127.0.0.1:9002"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9003","127.0.0.1:9004"], "role": "READ"},{"addresses": ["127.0.0.1:9005"], "role": "ROUTE"}]]
9+
SUCCESS {}

test/v1/routing.driver.boltkit.it.js

+42
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,48 @@ describe('routing driver', () => {
16301630
});
16311631
});
16321632

1633+
it('should treat routing table with single router as valid', done => {
1634+
if (!boltkit.BoltKitSupport) {
1635+
done();
1636+
return;
1637+
}
1638+
1639+
const kit = new boltkit.BoltKit();
1640+
const router = kit.start('./test/resources/boltkit/discover_one_router.script', 9010);
1641+
const reader1 = kit.start('./test/resources/boltkit/read_server.script', 9003);
1642+
const reader2 = kit.start('./test/resources/boltkit/read_server.script', 9004);
1643+
1644+
kit.run(() => {
1645+
const driver = newDriver('bolt+routing://127.0.0.1:9010');
1646+
const session = driver.session(READ);
1647+
1648+
session.run('MATCH (n) RETURN n.name').then(result1 => {
1649+
expect(result1.records.length).toEqual(3);
1650+
expect(result1.summary.server.address).toEqual('127.0.0.1:9003');
1651+
1652+
session.run('MATCH (n) RETURN n.name').then(result2 => {
1653+
expect(result2.records.length).toEqual(3);
1654+
expect(result2.summary.server.address).toEqual('127.0.0.1:9004');
1655+
1656+
session.close(() => {
1657+
driver.close();
1658+
router.exit(code1 => {
1659+
1660+
reader1.exit(code2 => {
1661+
reader2.exit(code3 => {
1662+
expect(code1).toEqual(0);
1663+
expect(code2).toEqual(0);
1664+
expect(code3).toEqual(0);
1665+
done();
1666+
});
1667+
});
1668+
});
1669+
});
1670+
});
1671+
});
1672+
});
1673+
});
1674+
16331675
function moveNextDateNow30SecondsForward() {
16341676
const currentTime = Date.now();
16351677
hijackNextDateNowCall(currentTime + 30 * 1000 + 1);

0 commit comments

Comments
 (0)