Compare commits
4 Commits
47ba983613
...
63a0891240
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 63a0891240 | |
Vitaliy Filippov | 40a3863039 | |
Vitaliy Filippov | d7fabbeb82 | |
Vitaliy Filippov | ae4e0c4106 |
|
@ -332,9 +332,9 @@ class AntiCluster
|
||||||
{
|
{
|
||||||
if (path == 'kv_txn')
|
if (path == 'kv_txn')
|
||||||
{
|
{
|
||||||
return ((!data.compare || !data.compare.length) &&
|
return (data.compare && data.compare.length ||
|
||||||
(!data.success || !data.success.filter(f => f.request_put || f.requestPut || f.request_delete_range || f.requestDeleteRange).length) &&
|
data.success && data.success.filter(f => f.request_put || f.requestPut || f.request_delete_range || f.requestDeleteRange).length ||
|
||||||
(!data.failure || !data.failure.filter(f => f.request_put || f.requestPut || f.request_delete_range || f.requestDeleteRange).length));
|
data.failure && data.failure.filter(f => f.request_put || f.requestPut || f.request_delete_range || f.requestDeleteRange).length);
|
||||||
}
|
}
|
||||||
return path != 'kv_range';
|
return path != 'kv_range';
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ License: Mozilla Public License 2.0 or Vitastor Network Public License 1.1
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
${process.argv[0]} ${process.argv[1]} \
|
${process.argv[0]} ${process.argv[1]} \n\
|
||||||
[--cert ssl.crt] [--key ssl.key] [--port 12379] \
|
[--cert ssl.crt] [--key ssl.key] [--port 12379] \n\
|
||||||
[--data data.gz] [--persist-filter ./filter.js] [--persist_interval 500] \
|
[--data data.gz] [--persist-filter ./filter.js] [--persist_interval 500] \n\
|
||||||
[--node_id node1 --cluster_key abcdef --cluster node1=http://localhost:12379,node2=http://localhost:12380,node3=http://localhost:12381] \
|
[--node_id node1 --cluster_key abcdef --cluster node1=http://localhost:12379,node2=http://localhost:12380,node3=http://localhost:12381] \n\
|
||||||
[other options]
|
[other options]
|
||||||
|
|
||||||
Supported etcd REST APIs:
|
Supported etcd REST APIs:
|
||||||
|
@ -43,6 +43,9 @@ HTTP:
|
||||||
Require TLS client certificates signed by <ca> or by default CA to connect.
|
Require TLS client certificates signed by <ca> or by default CA to connect.
|
||||||
--ws_keepalive_interval 30000
|
--ws_keepalive_interval 30000
|
||||||
Client websocket ping (keepalive) interval in milliseconds
|
Client websocket ping (keepalive) interval in milliseconds
|
||||||
|
--merge_watches 1
|
||||||
|
Antietcd merges all watcher events into a single websocket message to provide
|
||||||
|
more ordering/transaction guarantees. Set to 0 to disable this behaviour.
|
||||||
|
|
||||||
Persistence:
|
Persistence:
|
||||||
|
|
||||||
|
@ -105,7 +108,6 @@ function parse()
|
||||||
options[arg.substr(2)] = process.argv[++i];
|
options[arg.substr(2)] = process.argv[++i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options['stale_read'] = options['stale_read'] === '1' || options['stale_read'] === 'yes' || options['stale_read'] === 'true';
|
|
||||||
if (options['persist_filter'])
|
if (options['persist_filter'])
|
||||||
{
|
{
|
||||||
options['persist_filter'] = require(options['persist_filter'])(options);
|
options['persist_filter'] = require(options['persist_filter'])(options);
|
||||||
|
|
18
antietcd.js
18
antietcd.js
|
@ -24,6 +24,8 @@ class AntiEtcd extends EventEmitter
|
||||||
constructor(cfg)
|
constructor(cfg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
cfg['merge_watches'] = !('merge_watches' in cfg) || is_true(cfg['merge_watches']);
|
||||||
|
cfg['stale_read'] = !('stale_read' in cfg) || is_true(cfg['stale_read']);
|
||||||
this.clients = {};
|
this.clients = {};
|
||||||
this.client_id = 1;
|
this.client_id = 1;
|
||||||
this.etctree = new EtcTree(true);
|
this.etctree = new EtcTree(true);
|
||||||
|
@ -120,7 +122,7 @@ class AntiEtcd extends EventEmitter
|
||||||
let done = 0;
|
let done = 0;
|
||||||
await new Promise((allOk, allNo) =>
|
await new Promise((allOk, allNo) =>
|
||||||
{
|
{
|
||||||
res.map(promise => promise.then(res =>
|
res.map(promise => promise.then(r =>
|
||||||
{
|
{
|
||||||
if ((++done) == res.length)
|
if ((++done) == res.length)
|
||||||
allOk();
|
allOk();
|
||||||
|
@ -411,9 +413,9 @@ class AntiEtcd extends EventEmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
// public watch API
|
// public watch API
|
||||||
async create_watch(params, callback)
|
async create_watch(params, callback, stream_id)
|
||||||
{
|
{
|
||||||
const watch = this.etctree.api_create_watch({ ...params, watch_id: null }, callback);
|
const watch = this.etctree.api_create_watch({ ...params, watch_id: null }, callback, stream_id);
|
||||||
if (!watch.created)
|
if (!watch.created)
|
||||||
{
|
{
|
||||||
throw new RequestError(400, 'Requested watch revision is compacted', { compact_revision: watch.compact_revision });
|
throw new RequestError(400, 'Requested watch revision is compacted', { compact_revision: watch.compact_revision });
|
||||||
|
@ -478,7 +480,7 @@ class AntiEtcd extends EventEmitter
|
||||||
return this.etctree.api_keepalive_lease(data);
|
return this.etctree.api_keepalive_lease(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handle_maintenance_status(data)
|
_handle_maintenance_status(/*data*/)
|
||||||
{
|
{
|
||||||
const raft = this.cluster && this.cluster.raft;
|
const raft = this.cluster && this.cluster.raft;
|
||||||
return {
|
return {
|
||||||
|
@ -516,8 +518,9 @@ class AntiEtcd extends EventEmitter
|
||||||
const create_request = msg.create_request;
|
const create_request = msg.create_request;
|
||||||
if (!create_request.watch_id || !client.watches[create_request.watch_id])
|
if (!create_request.watch_id || !client.watches[create_request.watch_id])
|
||||||
{
|
{
|
||||||
|
client.send_cb = client.send_cb || (msg => socket.send(JSON.stringify(msg)));
|
||||||
const watch = this.etctree.api_create_watch(
|
const watch = this.etctree.api_create_watch(
|
||||||
{ ...create_request, watch_id: null }, (msg) => socket.send(JSON.stringify(msg))
|
{ ...create_request, watch_id: null }, client.send_cb, (this.cfg.merge_watches ? 'C'+client_id : null)
|
||||||
);
|
);
|
||||||
if (!watch.created)
|
if (!watch.created)
|
||||||
{
|
{
|
||||||
|
@ -569,6 +572,11 @@ class AntiEtcd extends EventEmitter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_true(s)
|
||||||
|
{
|
||||||
|
return s === true || s === 1 || s === '1' || s === 'yes' || s === 'true' || s === 'on';
|
||||||
|
}
|
||||||
|
|
||||||
AntiEtcd.RequestError = RequestError;
|
AntiEtcd.RequestError = RequestError;
|
||||||
|
|
||||||
AntiEtcd.VERSION = VERSION;
|
AntiEtcd.VERSION = VERSION;
|
||||||
|
|
13
etctree.js
13
etctree.js
|
@ -544,7 +544,7 @@ class EtcTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api_create_watch(req, send)
|
api_create_watch(req, send, stream_id)
|
||||||
{
|
{
|
||||||
const { parts, all } = this._get_range(req);
|
const { parts, all } = this._get_range(req);
|
||||||
if (req.start_revision && this.compact_revision && this.compact_revision > req.start_revision)
|
if (req.start_revision && this.compact_revision && this.compact_revision > req.start_revision)
|
||||||
|
@ -566,6 +566,7 @@ class EtcTree
|
||||||
this.watchers[watch_id] = {
|
this.watchers[watch_id] = {
|
||||||
paths: [],
|
paths: [],
|
||||||
send,
|
send,
|
||||||
|
stream_id,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.watchers[watch_id].paths.push(parts);
|
this.watchers[watch_id].paths.push(parts);
|
||||||
|
@ -667,15 +668,15 @@ class EtcTree
|
||||||
{
|
{
|
||||||
if (this.watchers[wid])
|
if (this.watchers[wid])
|
||||||
{
|
{
|
||||||
by_watcher[wid] = by_watcher[wid] || { header: { revision: this.mod_revision }, events: {} };
|
const stream_id = this.watchers[wid].stream_id || wid;
|
||||||
by_watcher[wid].events[notif.key] = conv;
|
by_watcher[stream_id] = by_watcher[stream_id] || { send: this.watchers[wid].send, events: {} };
|
||||||
|
by_watcher[stream_id].events[notif.key] = conv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const wid in by_watcher)
|
for (const stream_id in by_watcher)
|
||||||
{
|
{
|
||||||
by_watcher[wid].events = Object.values(by_watcher[wid].events);
|
by_watcher[stream_id].send({ result: { header: { revision: this.mod_revision }, events: Object.values(by_watcher[stream_id].events) } });
|
||||||
this.watchers[wid].send({ result: by_watcher[wid] });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,38 @@ tests['watch'] = async () =>
|
||||||
t.destroy();
|
t.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tests['merge watch'] = async () =>
|
||||||
|
{
|
||||||
|
const t = new EtcTree();
|
||||||
|
const sent = [];
|
||||||
|
const send = (event) => sent.push(event);
|
||||||
|
expect(
|
||||||
|
await t.api_txn({ success: [ { request_put: { key: '/vitastor//config/pgs', value: { items: {} } } } ] }),
|
||||||
|
{ header: { revision: 1 }, succeeded: true, responses: [ { response_put: {} } ] }
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
t.api_create_watch({ watch_id: 1, key: '/vitastor/config/pgs' }, send, 'X1' /* stream_id */),
|
||||||
|
{ header: { revision: 1 }, watch_id: 1, created: true }
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
t.api_create_watch({ watch_id: 2, key: '/vitastor/pg/history/', range_end: '/vitastor/pg/history0' }, send, 'X1' /* stream_id */),
|
||||||
|
{ header: { revision: 1 }, watch_id: 2, created: true },
|
||||||
|
);
|
||||||
|
expect(sent, []);
|
||||||
|
expect(
|
||||||
|
await t.api_txn({ success: [
|
||||||
|
{ request_put: { key: '/vitastor/config/pgs', value: { items: { 1: { 1: { osd_set: [ 1, 2, 3 ] } } } } } },
|
||||||
|
{ request_put: { key: '/vitastor/pg/history/1/1', value: { all_peers: [ 1, 2, 3, 4, 5 ] } } },
|
||||||
|
] }),
|
||||||
|
{ header: { revision: 2 }, succeeded: true, responses: [ { response_put: {} }, { response_put: {} } ] }
|
||||||
|
);
|
||||||
|
expect(sent, [ { result: { header: { revision: 2 }, events: [
|
||||||
|
{ type: 'PUT', kv: { key: '/vitastor/config/pgs', value: { items: { 1: { 1: { osd_set: [ 1, 2, 3 ] } } } }, mod_revision: 2 } },
|
||||||
|
{ type: 'PUT', kv: { key: '/vitastor/pg/history/1/1', value: { all_peers: [ 1, 2, 3, 4, 5 ] }, mod_revision: 2 } },
|
||||||
|
] } } ]);
|
||||||
|
t.destroy();
|
||||||
|
};
|
||||||
|
|
||||||
tests['lease'] = async () =>
|
tests['lease'] = async () =>
|
||||||
{
|
{
|
||||||
const t = new EtcTree();
|
const t = new EtcTree();
|
||||||
|
|
Loading…
Reference in New Issue