antietcd 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/antietcd.js +27 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ Simplistic miniature etcd replacement based on [TinyRaft](https://git.yourcmc.ru
|
|
|
27
27
|
- [/v3/lease/grant](#v3-lease-grant)
|
|
28
28
|
- [/v3/lease/keepalive](#v3-lease-keepalive)
|
|
29
29
|
- [/v3/lease/revoke or /v3/kv/lease/revoke](#v3-lease-revoke-or-v3-kv-lease-revoke)
|
|
30
|
+
- [/v3/maintenance/status](#v3-maintenance-status)
|
|
30
31
|
- [Websocket-based watch APIs](#websocket-based-watch-apis)
|
|
31
32
|
- [HTTP Error Codes](#http-error-codes)
|
|
32
33
|
|
|
@@ -450,6 +451,31 @@ type LeaseRevokeResponse = {
|
|
|
450
451
|
}
|
|
451
452
|
```
|
|
452
453
|
|
|
454
|
+
### /v3/maintenance/status
|
|
455
|
+
|
|
456
|
+
Request:
|
|
457
|
+
|
|
458
|
+
```{}```
|
|
459
|
+
|
|
460
|
+
Response:
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
type MaintenanceStatusResponse = {
|
|
464
|
+
header: {
|
|
465
|
+
member_id?: string,
|
|
466
|
+
revision: number,
|
|
467
|
+
compact_revision: number,
|
|
468
|
+
raft_term?: number,
|
|
469
|
+
},
|
|
470
|
+
version: string,
|
|
471
|
+
leader?: string,
|
|
472
|
+
raftTerm?: string,
|
|
473
|
+
raftState?: 'leader'|'follower'|'candidate',
|
|
474
|
+
// dbSize actually reports process memory usage
|
|
475
|
+
dbSize: number,
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
453
479
|
### Websocket-based watch APIs
|
|
454
480
|
|
|
455
481
|
Client-to-server message format:
|
package/antietcd.js
CHANGED
|
@@ -181,13 +181,13 @@ class AntiEtcd extends EventEmitter
|
|
|
181
181
|
if (e instanceof RequestError)
|
|
182
182
|
{
|
|
183
183
|
code = e.code;
|
|
184
|
-
reply = e.message;
|
|
184
|
+
reply = e.message+'\n';
|
|
185
185
|
}
|
|
186
186
|
else
|
|
187
187
|
{
|
|
188
188
|
console.error(e);
|
|
189
189
|
code = 500;
|
|
190
|
-
reply = 'Internal error: '+e.message;
|
|
190
|
+
reply = 'Internal error: '+e.message+'\n';
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
try
|
|
@@ -329,7 +329,7 @@ class AntiEtcd extends EventEmitter
|
|
|
329
329
|
if ((e instanceof RequestError) && e.code == 404)
|
|
330
330
|
{
|
|
331
331
|
throw new RequestError(404, 'Supported APIs: /v3/kv/txn, /v3/kv/range, /v3/kv/put, /v3/kv/deleterange, '+
|
|
332
|
-
'/v3/lease/grant, /v3/lease/revoke, /v3/kv/lease/revoke, /v3/lease/keepalive');
|
|
332
|
+
'/v3/lease/grant, /v3/lease/revoke, /v3/kv/lease/revoke, /v3/lease/keepalive, /v3/maintenance/status');
|
|
333
333
|
}
|
|
334
334
|
else
|
|
335
335
|
{
|
|
@@ -345,7 +345,7 @@ class AntiEtcd extends EventEmitter
|
|
|
345
345
|
{
|
|
346
346
|
throw new RequestError(502, 'Server is stopping');
|
|
347
347
|
}
|
|
348
|
-
if (path !== 'dump' &&
|
|
348
|
+
if (this.cluster && path !== 'dump' && path != 'maintenance_status')
|
|
349
349
|
{
|
|
350
350
|
const res = await this.cluster.checkRaftState(
|
|
351
351
|
path,
|
|
@@ -428,7 +428,7 @@ class AntiEtcd extends EventEmitter
|
|
|
428
428
|
{
|
|
429
429
|
throw new RequestError(400, 'Watch not found');
|
|
430
430
|
}
|
|
431
|
-
this.etctree.api_cancel_watch(
|
|
431
|
+
this.etctree.api_cancel_watch(mapped_id);
|
|
432
432
|
delete this.api_watches[watch_id];
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -476,6 +476,24 @@ class AntiEtcd extends EventEmitter
|
|
|
476
476
|
return this.etctree.api_keepalive_lease(data);
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
+
_handle_maintenance_status(data)
|
|
480
|
+
{
|
|
481
|
+
const raft = this.cluster && this.cluster.raft;
|
|
482
|
+
return {
|
|
483
|
+
header: {
|
|
484
|
+
member_id: this.cfg.node_id || undefined,
|
|
485
|
+
revision: this.etctree.mod_revision,
|
|
486
|
+
compact_revision: this.etctree.compact_revision || 0,
|
|
487
|
+
raft_term: raft && raft.term || undefined,
|
|
488
|
+
},
|
|
489
|
+
version: 'antietcd '+AntiEtcd.VERSION,
|
|
490
|
+
leader: raft && raft.leader || undefined,
|
|
491
|
+
raftTerm: raft && raft.term || undefined,
|
|
492
|
+
raftState: raft && raft.state || undefined,
|
|
493
|
+
dbSize: process.memoryUsage().heapUsed,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
479
497
|
// eslint-disable-next-line no-unused-vars
|
|
480
498
|
_handle_dump(data)
|
|
481
499
|
{
|
|
@@ -514,7 +532,7 @@ class AntiEtcd extends EventEmitter
|
|
|
514
532
|
const mapped_id = client.watches[msg.cancel_request.watch_id];
|
|
515
533
|
if (mapped_id)
|
|
516
534
|
{
|
|
517
|
-
this.etctree.api_cancel_watch(
|
|
535
|
+
this.etctree.api_cancel_watch(mapped_id);
|
|
518
536
|
delete client.watches[msg.cancel_request.watch_id];
|
|
519
537
|
socket.send(JSON.stringify({ result: { header: { revision: this.etctree.mod_revision }, watch_id: msg.cancel_request.watch_id, canceled: true } }));
|
|
520
538
|
}
|
|
@@ -542,11 +560,13 @@ class AntiEtcd extends EventEmitter
|
|
|
542
560
|
for (const watch_id in this.clients[client_id].watches)
|
|
543
561
|
{
|
|
544
562
|
const mapped_id = this.clients[client_id].watches[watch_id];
|
|
545
|
-
this.etctree.api_cancel_watch(
|
|
563
|
+
this.etctree.api_cancel_watch(mapped_id);
|
|
546
564
|
}
|
|
547
565
|
}
|
|
548
566
|
}
|
|
549
567
|
|
|
550
568
|
AntiEtcd.RequestError = RequestError;
|
|
551
569
|
|
|
570
|
+
AntiEtcd.VERSION = '1.0.7';
|
|
571
|
+
|
|
552
572
|
module.exports = AntiEtcd;
|