Compare commits
1 Commits
23062dde58
...
bf7dd6646d
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | bf7dd6646d |
|
@ -100,9 +100,6 @@ Specify <ca> = <cert> if your certificate is self-signed.</dd>
|
||||||
<dt>--ws_keepalive_interval 30000</dt>
|
<dt>--ws_keepalive_interval 30000</dt>
|
||||||
<dd>Client websocket ping (keepalive) interval in milliseconds</dd>
|
<dd>Client websocket ping (keepalive) interval in milliseconds</dd>
|
||||||
|
|
||||||
<dt>--use_base64 1</dt>
|
|
||||||
<dd>Use base64 encoding of keys and values, like in etcd (enabled by default).</dd>
|
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
### Persistence
|
### Persistence
|
||||||
|
|
|
@ -43,8 +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
|
||||||
--use_base64 1
|
|
||||||
Use base64 encoding of keys and values, like in etcd (enabled by default).
|
|
||||||
|
|
||||||
Persistence:
|
Persistence:
|
||||||
|
|
||||||
|
@ -107,14 +105,7 @@ 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';
|
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);
|
||||||
|
|
55
antietcd.js
55
antietcd.js
|
@ -22,14 +22,6 @@ class AntiEtcd extends EventEmitter
|
||||||
constructor(cfg)
|
constructor(cfg)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
if (!('use_base64' in cfg))
|
|
||||||
{
|
|
||||||
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);
|
||||||
|
@ -140,11 +132,11 @@ class AntiEtcd extends EventEmitter
|
||||||
if (!this.cluster)
|
if (!this.cluster)
|
||||||
{
|
{
|
||||||
// Run deletion compaction without followers
|
// Run deletion compaction without followers
|
||||||
const mod_revision = this.etctree.mod_revision;
|
const mod_revision = this.antietcd.etctree.mod_revision;
|
||||||
if (mod_revision - this.etctree.compact_revision > (this.cfg.compact_revisions||1000)*2)
|
if (mod_revision - this.antietcd.etctree.compact_revision > (this.cfg.compact_revisions||1000)*2)
|
||||||
{
|
{
|
||||||
const revision = mod_revision - (this.cfg.compact_revisions||1000);
|
const revision = mod_revision - (this.cfg.compact_revisions||1000);
|
||||||
this.etctree.compact(revision);
|
this.antietcd.etctree.compact(revision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -419,7 +411,7 @@ class AntiEtcd extends EventEmitter
|
||||||
// public watch API
|
// public watch API
|
||||||
async create_watch(params, callback)
|
async create_watch(params, callback)
|
||||||
{
|
{
|
||||||
const watch = this.etctree.api_create_watch(this._encodeWatch(params), (msg) => callback(this._encodeMsg(msg)));
|
const watch = this.etctree.api_create_watch({ ...params, watch_id: null }, callback);
|
||||||
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 });
|
||||||
|
@ -542,7 +534,15 @@ 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])
|
||||||
{
|
{
|
||||||
const watch = this.etctree.api_create_watch(this._encodeWatch(create_request), (msg) => socket.send(JSON.stringify(this._encodeMsg(msg))));
|
const req = { ...create_request, watch_id: null };
|
||||||
|
if (this.cfg.use_base64)
|
||||||
|
{
|
||||||
|
if (req.key != null)
|
||||||
|
req.key = de64(req.key);
|
||||||
|
if (req.range_end != null)
|
||||||
|
req.range_end = de64(req.range_end);
|
||||||
|
}
|
||||||
|
const watch = this.etctree.api_create_watch(req, (msg) => this.sendToSocket(socket, msg));
|
||||||
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 } }));
|
||||||
|
@ -579,35 +579,6 @@ class AntiEtcd extends EventEmitter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_encodeWatch(create_request)
|
|
||||||
{
|
|
||||||
const req = { ...create_request, watch_id: null };
|
|
||||||
if (this.cfg.use_base64)
|
|
||||||
{
|
|
||||||
if (req.key != null)
|
|
||||||
req.key = de64(req.key);
|
|
||||||
if (req.range_end != null)
|
|
||||||
req.range_end = de64(req.range_end);
|
|
||||||
}
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
|
|
||||||
_encodeMsg(msg)
|
|
||||||
{
|
|
||||||
if (this.cfg.use_base64 && msg.result && msg.result.events)
|
|
||||||
{
|
|
||||||
return { ...msg, result: { ...msg.result, events: msg.result.events.map(ev => ({
|
|
||||||
...ev,
|
|
||||||
kv: !ev.kv ? ev.kv : {
|
|
||||||
...ev.kv,
|
|
||||||
key: b64(ev.kv.key),
|
|
||||||
value: b64(ev.kv.value),
|
|
||||||
},
|
|
||||||
})) } };
|
|
||||||
}
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
_unsubscribeClient(client_id)
|
_unsubscribeClient(client_id)
|
||||||
{
|
{
|
||||||
if (!this.clients[client_id])
|
if (!this.clients[client_id])
|
||||||
|
|
|
@ -8,7 +8,7 @@ const zlib = require('zlib');
|
||||||
|
|
||||||
const stableStringify = require('./stable-stringify.js');
|
const stableStringify = require('./stable-stringify.js');
|
||||||
const EtcTree = require('./etctree.js');
|
const EtcTree = require('./etctree.js');
|
||||||
const { runCallbacks } = require('./common.js');
|
const { de64, runCallbacks } = require('./common.js');
|
||||||
|
|
||||||
class AntiPersistence
|
class AntiPersistence
|
||||||
{
|
{
|
||||||
|
@ -60,18 +60,20 @@ class AntiPersistence
|
||||||
if (ev.lease)
|
if (ev.lease)
|
||||||
{
|
{
|
||||||
// Values with lease are never persisted
|
// Values with lease are never persisted
|
||||||
if (this.prev_value[ev.key] !== undefined)
|
const key = de64(ev.key);
|
||||||
|
if (this.prev_value[key] !== undefined)
|
||||||
{
|
{
|
||||||
delete this.prev_value[ev.key];
|
delete this.prev_value[key];
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const filtered = this.cfg.persist_filter(ev.key, ev.value == null ? undefined : ev.value);
|
const key = de64(ev.key);
|
||||||
if (!EtcTree.eq(filtered, this.prev_value[ev.key]))
|
const filtered = this.cfg.persist_filter(key, ev.value == null ? undefined : de64(ev.value));
|
||||||
|
if (!EtcTree.eq(filtered, this.prev_value[key]))
|
||||||
{
|
{
|
||||||
this.prev_value[ev.key] = filtered;
|
this.prev_value[key] = filtered;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ function b64(k)
|
||||||
{
|
{
|
||||||
if (k == null) // null or undefined
|
if (k == null) // null or undefined
|
||||||
return k;
|
return k;
|
||||||
return Buffer.from(k).toString('base64');
|
return this.use_base64 ? Buffer.from(k).toString('base64') : k;
|
||||||
}
|
}
|
||||||
|
|
||||||
function runCallbacks(obj, key, new_value)
|
function runCallbacks(obj, key, new_value)
|
||||||
|
|
|
@ -573,7 +573,7 @@ class EtcTree
|
||||||
});
|
});
|
||||||
this.active_immediate.push(imm);
|
this.active_immediate.push(imm);
|
||||||
}
|
}
|
||||||
return { header: { revision: this.mod_revision }, watch_id, created: true };
|
return { watch_id, created: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
_get_modified(events, cur, prefix, min_rev)
|
_get_modified(events, cur, prefix, min_rev)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "antietcd",
|
"name": "antietcd",
|
||||||
"version": "1.0.1",
|
"version": "1.0.0",
|
||||||
"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