Compare commits
1 Commits
76fe5ea44e
...
f6710b52c3
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | f6710b52c3 |
28
README.md
28
README.md
|
@ -27,7 +27,6 @@ Simplistic miniature etcd replacement based on [TinyRaft](https://git.yourcmc.ru
|
||||||
- [/v3/lease/grant](#v3-lease-grant)
|
- [/v3/lease/grant](#v3-lease-grant)
|
||||||
- [/v3/lease/keepalive](#v3-lease-keepalive)
|
- [/v3/lease/keepalive](#v3-lease-keepalive)
|
||||||
- [/v3/lease/revoke or /v3/kv/lease/revoke](#v3-lease-revoke-or-v3-kv-lease-revoke)
|
- [/v3/lease/revoke or /v3/kv/lease/revoke](#v3-lease-revoke-or-v3-kv-lease-revoke)
|
||||||
- [/v3/maintenance/status](#v3-maintenance-status)
|
|
||||||
- [Websocket-based watch APIs](#websocket-based-watch-apis)
|
- [Websocket-based watch APIs](#websocket-based-watch-apis)
|
||||||
- [HTTP Error Codes](#http-error-codes)
|
- [HTTP Error Codes](#http-error-codes)
|
||||||
|
|
||||||
|
@ -454,33 +453,6 @@ type LeaseRevokeResponse = {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### /v3/maintenance/status
|
|
||||||
|
|
||||||
Request:
|
|
||||||
|
|
||||||
```{}```
|
|
||||||
|
|
||||||
Response:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
type MaintenanceStatusResponse = {
|
|
||||||
header: {
|
|
||||||
member_id?: string,
|
|
||||||
revision: number,
|
|
||||||
compact_revision: number,
|
|
||||||
raft_term?: number,
|
|
||||||
},
|
|
||||||
version: string,
|
|
||||||
cluster?: { [string]: string },
|
|
||||||
leader?: string,
|
|
||||||
followers?: string[],
|
|
||||||
raftTerm?: string,
|
|
||||||
raftState?: 'leader'|'follower'|'candidate',
|
|
||||||
// dbSize actually reports process memory usage
|
|
||||||
dbSize: number,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Websocket-based watch APIs
|
### Websocket-based watch APIs
|
||||||
|
|
||||||
Client-to-server message format:
|
Client-to-server message format:
|
||||||
|
|
|
@ -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]} \n\
|
${process.argv[0]} ${process.argv[1]} \
|
||||||
[--cert ssl.crt] [--key ssl.key] [--port 12379] \n\
|
[--cert ssl.crt] [--key ssl.key] [--port 12379] \
|
||||||
[--data data.gz] [--persist-filter ./filter.js] [--persist_interval 500] \n\
|
[--data data.gz] [--persist-filter ./filter.js] [--persist_interval 500] \
|
||||||
[--node_id node1 --cluster_key abcdef --cluster node1=http://localhost:12379,node2=http://localhost:12380,node3=http://localhost:12381] \n\
|
[--node_id node1 --cluster_key abcdef --cluster node1=http://localhost:12379,node2=http://localhost:12380,node3=http://localhost:12381] \
|
||||||
[other options]
|
[other options]
|
||||||
|
|
||||||
Supported etcd REST APIs:
|
Supported etcd REST APIs:
|
||||||
|
@ -43,9 +43,6 @@ 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.
|
|
||||||
--use_base64 1
|
--use_base64 1
|
||||||
Use base64 encoding of keys and values, like in etcd (enabled by default).
|
Use base64 encoding of keys and values, like in etcd (enabled by default).
|
||||||
|
|
||||||
|
@ -110,6 +107,14 @@ function parse()
|
||||||
options[arg.substr(2)] = process.argv[++i];
|
options[arg.substr(2)] = process.argv[++i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ('stale_read' in options)
|
||||||
|
{
|
||||||
|
options['stale_read'] = options['stale_read'] === '1' || options['stale_read'] === 'yes' || options['stale_read'] === 'true';
|
||||||
|
}
|
||||||
|
if ('use_base64' in options)
|
||||||
|
{
|
||||||
|
options['use_base64'] = options['use_base64'] === '1' || options['use_base64'] === 'yes' || options['use_base64'] === '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);
|
||||||
|
|
67
antietcd.js
67
antietcd.js
|
@ -17,16 +17,19 @@ const AntiPersistence = require('./antipersistence.js');
|
||||||
const AntiCluster = require('./anticluster.js');
|
const AntiCluster = require('./anticluster.js');
|
||||||
const { runCallbacks, de64, b64, RequestError } = require('./common.js');
|
const { runCallbacks, de64, b64, RequestError } = require('./common.js');
|
||||||
|
|
||||||
const VERSION = '1.0.9';
|
|
||||||
|
|
||||||
class AntiEtcd extends EventEmitter
|
class AntiEtcd extends EventEmitter
|
||||||
{
|
{
|
||||||
constructor(cfg)
|
constructor(cfg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
cfg['merge_watches'] = !('merge_watches' in cfg) || is_true(cfg['merge_watches']);
|
if (!('use_base64' in cfg))
|
||||||
cfg['stale_read'] = !('stale_read' in cfg) || is_true(cfg['stale_read']);
|
{
|
||||||
cfg['use_base64'] = !('use_base64' in cfg) || is_true(cfg['use_base64']);
|
cfg.use_base64 = 1;
|
||||||
|
}
|
||||||
|
if (!('stale_read' in cfg))
|
||||||
|
{
|
||||||
|
cfg.stale_read = 1;
|
||||||
|
}
|
||||||
this.clients = {};
|
this.clients = {};
|
||||||
this.client_id = 1;
|
this.client_id = 1;
|
||||||
this.etctree = new EtcTree(true);
|
this.etctree = new EtcTree(true);
|
||||||
|
@ -77,7 +80,7 @@ class AntiEtcd extends EventEmitter
|
||||||
{
|
{
|
||||||
this.server = http.createServer((req, res) => this._handleRequest(req, res));
|
this.server = http.createServer((req, res) => this._handleRequest(req, res));
|
||||||
}
|
}
|
||||||
this.wss = new ws.Server({ server: this.server });
|
this.wss = new ws.WebSocketServer({ server: this.server });
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
this.wss.on('connection', (conn, req) => this._startWebsocket(conn, null));
|
this.wss.on('connection', (conn, req) => this._startWebsocket(conn, null));
|
||||||
this.server.listen(this.cfg.port || 2379, this.cfg.ip || undefined);
|
this.server.listen(this.cfg.port || 2379, this.cfg.ip || undefined);
|
||||||
|
@ -123,7 +126,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(r =>
|
res.map(promise => promise.then(res =>
|
||||||
{
|
{
|
||||||
if ((++done) == res.length)
|
if ((++done) == res.length)
|
||||||
allOk();
|
allOk();
|
||||||
|
@ -186,13 +189,13 @@ class AntiEtcd extends EventEmitter
|
||||||
if (e instanceof RequestError)
|
if (e instanceof RequestError)
|
||||||
{
|
{
|
||||||
code = e.code;
|
code = e.code;
|
||||||
reply = e.message+'\n';
|
reply = e.message;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.error(e);
|
console.error(e);
|
||||||
code = 500;
|
code = 500;
|
||||||
reply = 'Internal error: '+e.message+'\n';
|
reply = 'Internal error: '+e.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
@ -334,7 +337,7 @@ class AntiEtcd extends EventEmitter
|
||||||
if ((e instanceof RequestError) && e.code == 404)
|
if ((e instanceof RequestError) && e.code == 404)
|
||||||
{
|
{
|
||||||
throw new RequestError(404, 'Supported APIs: /v3/kv/txn, /v3/kv/range, /v3/kv/put, /v3/kv/deleterange, '+
|
throw new RequestError(404, 'Supported APIs: /v3/kv/txn, /v3/kv/range, /v3/kv/put, /v3/kv/deleterange, '+
|
||||||
'/v3/lease/grant, /v3/lease/revoke, /v3/kv/lease/revoke, /v3/lease/keepalive, /v3/maintenance/status');
|
'/v3/lease/grant, /v3/lease/revoke, /v3/kv/lease/revoke, /v3/lease/keepalive');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -350,7 +353,7 @@ class AntiEtcd extends EventEmitter
|
||||||
{
|
{
|
||||||
throw new RequestError(502, 'Server is stopping');
|
throw new RequestError(502, 'Server is stopping');
|
||||||
}
|
}
|
||||||
if (this.cluster && path !== 'dump' && path != 'maintenance_status')
|
if (path !== 'dump' && this.cluster)
|
||||||
{
|
{
|
||||||
const res = await this.cluster.checkRaftState(
|
const res = await this.cluster.checkRaftState(
|
||||||
path,
|
path,
|
||||||
|
@ -414,9 +417,9 @@ class AntiEtcd extends EventEmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
// public watch API
|
// public watch API
|
||||||
async create_watch(params, callback, stream_id)
|
async create_watch(params, callback)
|
||||||
{
|
{
|
||||||
const watch = this.etctree.api_create_watch(this._encodeWatch(params), (msg) => callback(this._encodeMsg(msg)), stream_id);
|
const watch = this.etctree.api_create_watch(this._encodeWatch(params), (msg) => callback(this._encodeMsg(msg)));
|
||||||
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 });
|
||||||
|
@ -433,7 +436,7 @@ class AntiEtcd extends EventEmitter
|
||||||
{
|
{
|
||||||
throw new RequestError(400, 'Watch not found');
|
throw new RequestError(400, 'Watch not found');
|
||||||
}
|
}
|
||||||
this.etctree.api_cancel_watch(mapped_id);
|
this.etctree.api_cancel_watch({ watch_id: mapped_id });
|
||||||
delete this.api_watches[watch_id];
|
delete this.api_watches[watch_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,26 +524,6 @@ class AntiEtcd extends EventEmitter
|
||||||
return this.etctree.api_keepalive_lease(data);
|
return this.etctree.api_keepalive_lease(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handle_maintenance_status(/*data*/)
|
|
||||||
{
|
|
||||||
const raft = this.cluster && this.cluster.raft;
|
|
||||||
return {
|
|
||||||
header: {
|
|
||||||
member_id: this.cfg.node_id || undefined,
|
|
||||||
revision: this.etctree.mod_revision,
|
|
||||||
compact_revision: this.etctree.compact_revision || 0,
|
|
||||||
raft_term: raft && raft.term || undefined,
|
|
||||||
},
|
|
||||||
version: 'antietcd '+AntiEtcd.VERSION,
|
|
||||||
cluster: this.cfg.cluster || undefined,
|
|
||||||
leader: raft && raft.leader || undefined,
|
|
||||||
followers: raft && raft.followers || undefined,
|
|
||||||
raftTerm: raft && raft.term || undefined,
|
|
||||||
raftState: raft && raft.state || undefined,
|
|
||||||
dbSize: process.memoryUsage().heapUsed,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
_handle_dump(data)
|
_handle_dump(data)
|
||||||
{
|
{
|
||||||
|
@ -559,10 +542,7 @@ 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(this._encodeMsg(msg))));
|
const watch = this.etctree.api_create_watch(this._encodeWatch(create_request), (msg) => socket.send(JSON.stringify(this._encodeMsg(msg))));
|
||||||
const watch = this.etctree.api_create_watch(
|
|
||||||
this._encodeWatch(create_request), client.send_cb, (this.cfg.merge_watches ? 'C'+client_id : null)
|
|
||||||
);
|
|
||||||
if (!watch.created)
|
if (!watch.created)
|
||||||
{
|
{
|
||||||
socket.send(JSON.stringify({ result: { header: { revision: this.etctree.mod_revision }, watch_id: create_request.watch_id, ...watch } }));
|
socket.send(JSON.stringify({ result: { header: { revision: this.etctree.mod_revision }, watch_id: create_request.watch_id, ...watch } }));
|
||||||
|
@ -580,7 +560,7 @@ class AntiEtcd extends EventEmitter
|
||||||
const mapped_id = client.watches[msg.cancel_request.watch_id];
|
const mapped_id = client.watches[msg.cancel_request.watch_id];
|
||||||
if (mapped_id)
|
if (mapped_id)
|
||||||
{
|
{
|
||||||
this.etctree.api_cancel_watch(mapped_id);
|
this.etctree.api_cancel_watch({ watch_id: mapped_id });
|
||||||
delete client.watches[msg.cancel_request.watch_id];
|
delete client.watches[msg.cancel_request.watch_id];
|
||||||
socket.send(JSON.stringify({ result: { header: { revision: this.etctree.mod_revision }, watch_id: msg.cancel_request.watch_id, canceled: true } }));
|
socket.send(JSON.stringify({ result: { header: { revision: this.etctree.mod_revision }, watch_id: msg.cancel_request.watch_id, canceled: true } }));
|
||||||
}
|
}
|
||||||
|
@ -637,18 +617,11 @@ class AntiEtcd extends EventEmitter
|
||||||
for (const watch_id in this.clients[client_id].watches)
|
for (const watch_id in this.clients[client_id].watches)
|
||||||
{
|
{
|
||||||
const mapped_id = this.clients[client_id].watches[watch_id];
|
const mapped_id = this.clients[client_id].watches[watch_id];
|
||||||
this.etctree.api_cancel_watch(mapped_id);
|
this.etctree.api_cancel_watch({ watch_id: mapped_id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
module.exports = AntiEtcd;
|
module.exports = AntiEtcd;
|
||||||
|
|
20
etctree.js
20
etctree.js
|
@ -264,7 +264,7 @@ class EtcTree
|
||||||
{
|
{
|
||||||
cur_old.value = cur_new.value;
|
cur_old.value = cur_new.value;
|
||||||
const key_watchers = (cur_old.key_watchers ? [ ...watchers, ...(cur_old.key_watchers||[]) ] : watchers);
|
const key_watchers = (cur_old.key_watchers ? [ ...watchers, ...(cur_old.key_watchers||[]) ] : watchers);
|
||||||
const notify = { watchers: key_watchers, key, value: cur_new.value, mod_revision: cur_new.mod_revision };
|
const notify = { watchers: key_watchers, key: this.b64(key), value: this.b64(cur_new.value), mod_revision: cur_new.mod_revision };
|
||||||
if (cur_new.lease)
|
if (cur_new.lease)
|
||||||
{
|
{
|
||||||
notify.lease = cur_new.lease;
|
notify.lease = cur_new.lease;
|
||||||
|
@ -431,11 +431,6 @@ class EtcTree
|
||||||
{
|
{
|
||||||
this._delete_range({ key }, next_revision, notifications);
|
this._delete_range({ key }, next_revision, notifications);
|
||||||
}
|
}
|
||||||
if (this.leases[id].timer_id)
|
|
||||||
{
|
|
||||||
clearTimeout(this.leases[id].timer_id);
|
|
||||||
this.leases[id].timer_id = null;
|
|
||||||
}
|
|
||||||
delete this.leases[id];
|
delete this.leases[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +524,7 @@ class EtcTree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api_create_watch(req, send, stream_id)
|
api_create_watch(req, send)
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
@ -551,7 +546,6 @@ 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);
|
||||||
|
@ -653,15 +647,15 @@ class EtcTree
|
||||||
{
|
{
|
||||||
if (this.watchers[wid])
|
if (this.watchers[wid])
|
||||||
{
|
{
|
||||||
const stream_id = this.watchers[wid].stream_id || wid;
|
by_watcher[wid] = by_watcher[wid] || { header: { revision: this.mod_revision }, events: {} };
|
||||||
by_watcher[stream_id] = by_watcher[stream_id] || { send: this.watchers[wid].send, events: {} };
|
by_watcher[wid].events[notif.key] = conv;
|
||||||
by_watcher[stream_id].events[notif.key] = conv;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const stream_id in by_watcher)
|
for (const wid in by_watcher)
|
||||||
{
|
{
|
||||||
by_watcher[stream_id].send({ result: { header: { revision: this.mod_revision }, events: Object.values(by_watcher[stream_id].events) } });
|
by_watcher[wid].events = Object.values(by_watcher[wid].events);
|
||||||
|
this.watchers[wid].send({ result: by_watcher[wid] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ tests['read/write'] = async () =>
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
t.dump(false),
|
t.dump(false),
|
||||||
{"state":{"children":{"":{"children":{"vitastor":{"children":{"config":{"children":{"global":{"version":2,"mod_revision":2,"create_revision":1,"value":{"hello":"world2"}}}}}}}}}},"mod_revision":2,"compact_revision":0,"leases":{}}
|
{"state":{"children":{"":{"children":{"vitastor":{"children":{"config":{"children":{"global":{"version":2,"mod_revision":2,"create_revision":1,"value":{"hello":"world2"}}}}}}}}}},"mod_revision":2,"leases":{}}
|
||||||
);
|
);
|
||||||
t.destroy();
|
t.destroy();
|
||||||
};
|
};
|
||||||
|
@ -80,7 +80,7 @@ tests['watch'] = async () =>
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
t.api_create_watch({ watch_id: 1, key: '/vitastor/', range_end: '/vitastor0' }, send),
|
t.api_create_watch({ watch_id: 1, key: '/vitastor/', range_end: '/vitastor0' }, send),
|
||||||
{ header: { revision: 1 }, watch_id: 1, created: true }
|
{ watch_id: 1, created: true }
|
||||||
);
|
);
|
||||||
expect(sent, []);
|
expect(sent, []);
|
||||||
expect(
|
expect(
|
||||||
|
@ -91,38 +91,6 @@ 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();
|
||||||
|
@ -132,18 +100,18 @@ tests['lease'] = async () =>
|
||||||
expect(leaseID != null, true);
|
expect(leaseID != null, true);
|
||||||
expect(
|
expect(
|
||||||
await t.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.4' } } } ] }),
|
await t.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.4' } } } ] }),
|
||||||
{ header: { revision: 2 }, succeeded: true, responses: [ { response_put: {} } ] }
|
{ header: { revision: 1 }, succeeded: true, responses: [ { response_put: {} } ] }
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
t.api_create_watch({ watch_id: 1, key: '/vitastor/', range_end: '/vitastor0' }, send),
|
t.api_create_watch({ watch_id: 1, key: '/vitastor/', range_end: '/vitastor0' }, send),
|
||||||
{ header: { revision: 2 }, watch_id: 1, created: true }
|
{ watch_id: 1, created: true }
|
||||||
);
|
);
|
||||||
expect(sent, []);
|
expect(sent, []);
|
||||||
const dump = t.dump(false);
|
const dump = t.dump(false);
|
||||||
const expires = dump.leases[leaseID].expires;
|
const expires = dump.leases[leaseID].expires;
|
||||||
expect(dump, {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":1,"mod_revision":2,"create_revision":2,"value":{"ip":"1.2.3.4"}}}}}}}}}}}},"mod_revision":2,"compact_revision":0,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
expect(dump, {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":1,"mod_revision":1,"create_revision":1,"value":{"ip":"1.2.3.4"}}}}}}}}}}}},"mod_revision":1,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
||||||
await new Promise(ok => setTimeout(ok, 600));
|
await new Promise(ok => setTimeout(ok, 600));
|
||||||
expect(sent, [ { result: { header: { revision: 3 }, events: [ { type: 'DELETE', kv: { key: '/vitastor/osd/state/1', mod_revision: 3 } } ] } } ]);
|
expect(sent, [ { result: { header: { revision: 2 }, events: [ { type: 'DELETE', kv: { key: '/vitastor/osd/state/1', mod_revision: 2 } } ] } } ]);
|
||||||
t.pause_leases();
|
t.pause_leases();
|
||||||
t.load(dump);
|
t.load(dump);
|
||||||
expect(t.dump(false), dump);
|
expect(t.dump(false), dump);
|
||||||
|
@ -163,7 +131,7 @@ tests['update'] = async () =>
|
||||||
expect(leaseID != null, true);
|
expect(leaseID != null, true);
|
||||||
expect(
|
expect(
|
||||||
await t1.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.4' } } } ] }),
|
await t1.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.4' } } } ] }),
|
||||||
{ header: { revision: 2 }, succeeded: true, responses: [ { response_put: {} } ] }
|
{ header: { revision: 1 }, succeeded: true, responses: [ { response_put: {} } ] }
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
await t2.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', value: { ip: '1.2.3.6' } } } ] }),
|
await t2.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', value: { ip: '1.2.3.6' } } } ] }),
|
||||||
|
@ -171,15 +139,15 @@ tests['update'] = async () =>
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
await t1.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.5' } } } ] }),
|
await t1.api_txn({ success: [ { request_put: { key: '/vitastor/osd/state/1', lease: leaseID, value: { ip: '1.2.3.5' } } } ] }),
|
||||||
{ header: { revision: 3 }, succeeded: true, responses: [ { response_put: {} } ] }
|
{ header: { revision: 2 }, succeeded: true, responses: [ { response_put: {} } ] }
|
||||||
);
|
);
|
||||||
let dump2 = t2.dump();
|
let dump2 = t2.dump();
|
||||||
t2.load(t1.dump(), true);
|
t2.load(t1.dump(), true);
|
||||||
t1.load(dump2, true);
|
t1.load(dump2, true);
|
||||||
let dump = t2.dump(false);
|
let dump = t2.dump(false);
|
||||||
let expires = dump.leases[leaseID].expires;
|
let expires = dump.leases[leaseID].expires;
|
||||||
expect(dump, {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":2,"mod_revision":3,"create_revision":2,"value":{"ip":"1.2.3.5"}}}}}}}}}}}},"mod_revision":3,"compact_revision":0,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
expect(dump, {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":2,"mod_revision":2,"create_revision":1,"value":{"ip":"1.2.3.5"}}}}}}}}}}}},"mod_revision":2,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
||||||
expect(t1.dump(false), {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":2,"mod_revision":3,"create_revision":2,"value":{"ip":"1.2.3.5"}}}}}}}}}}}},"mod_revision":3,"compact_revision":0,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
expect(t1.dump(false), {"state":{"children":{"":{"children":{"vitastor":{"children":{"osd":{"children":{"state":{"children":{"1":{"lease":leaseID,"version":2,"mod_revision":2,"create_revision":1,"value":{"ip":"1.2.3.5"}}}}}}}}}}}},"mod_revision":2,"leases":{[leaseID]:{"ttl":0.5,"expires":expires}}});
|
||||||
t1.destroy();
|
t1.destroy();
|
||||||
t2.destroy();
|
t2.destroy();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "antietcd",
|
"name": "antietcd",
|
||||||
"version": "1.0.9",
|
"version": "1.0.4",
|
||||||
"description": "Simplistic etcd replacement based on TinyRaft",
|
"description": "Simplistic etcd replacement based on TinyRaft",
|
||||||
"main": "antietcd.js",
|
"main": "antietcd.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue