Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pro 2680/aerospike integration #4

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
3124d0d
Transition to docker dev environment, rewrite API for async, support …
bdentino Jun 6, 2019
8c1dab8
Merge pull request #1 from finboxio/v1.0
bdentino Jun 6, 2019
2b2af0e
Update changelog
bdentino Jun 6, 2019
a592511
1.0.0
bdentino Jun 6, 2019
fb5bab8
Queue close until next tick
bdentino Jun 13, 2019
e777ae7
Update changelog
bdentino Jun 13, 2019
17e0bae
1.0.1
bdentino Jun 13, 2019
2832744
Add v8 serialization for improved performance
bdentino Aug 19, 2019
0cb5a21
v1.1.0
bdentino Aug 19, 2019
f503110
Update mongo driver and allow user to provide mongo client
bdentino Sep 29, 2019
77608d6
v1.2.0
bdentino Sep 29, 2019
80885b7
Ensure mongo collection is created before writing
bdentino Sep 29, 2019
955d909
v1.2.1
bdentino Sep 29, 2019
08e1262
Fix mongo deprecation warnings
bdentino Sep 29, 2019
f469b0c
v1.2.2
bdentino Sep 29, 2019
90ba76d
Support for mongodb when transactions are not available
bdentino Sep 30, 2019
bd9fba4
Add tests for mongo replset
bdentino Sep 30, 2019
4bb210d
v1.3.0
bdentino Sep 30, 2019
c3c6af2
Fix race condition on mongo collection verification
bdentino Sep 30, 2019
85306e0
v1.3.1
bdentino Sep 30, 2019
b5bccec
Detect mongo session support
bdentino Sep 30, 2019
c7752df
v1.3.2
bdentino Sep 30, 2019
c595e84
Support get ttl
bdentino May 20, 2020
0df0f24
2.0.0
bdentino May 20, 2020
02a6569
Update changelog
bdentino May 20, 2020
b146d45
Add rtl option to retrieval
bdentino May 20, 2020
80fa682
update changelog
bdentino May 20, 2020
62b9fb9
update changelog
bdentino May 20, 2020
39638ab
2.1.0
bdentino May 20, 2020
5e5513a
Fix custom retrieval ttl = 0, tags when no prefixes provided
bdentino May 20, 2020
e51aadf
update changelog
bdentino May 20, 2020
805ab83
2.1.1
bdentino May 20, 2020
e1017af
Expose plugin and switch to native mongo driver
bdentino May 21, 2020
2ec4995
Update changelog
bdentino May 21, 2020
a49369a
2.1.2
bdentino May 21, 2020
44e9d7e
Update performance tests
bdentino May 28, 2020
deb6e89
improve performance of memory tags
bdentino May 28, 2020
8b2ef59
Update changelog
bdentino May 28, 2020
e70419b
2.1.3
bdentino May 28, 2020
eb8d586
Do not call connect on connecting mongo client
bdentino May 28, 2020
87d7420
Update changelog
bdentino May 28, 2020
296c0b6
2.1.4
bdentino May 28, 2020
fdd7358
Fix mongo connection bug
bdentino Jun 12, 2020
ef84a66
2.1.5
bdentino Jun 12, 2020
66cc2d9
Update changelog
bdentino Jun 12, 2020
4259879
Fix for promisified mongo clients
bdentino Jun 29, 2020
427e3b8
2.1.6
bdentino Jun 29, 2020
9b49980
Support for disabling mongo read transactions
bdentino Sep 30, 2020
3cdcb46
2.2.0
bdentino Sep 30, 2020
148c2ab
Fix syntax err
bdentino Sep 30, 2020
4fdc37b
2.2.1
bdentino Sep 30, 2020
2f95909
Error handling if mongo is closed while listing collections
bdentino Oct 16, 2020
627591b
2.2.2
bdentino Oct 16, 2020
f0ba65e
Error handling if mongo is closed while listing collections
bdentino Oct 16, 2020
3643688
2.2.3
bdentino Oct 16, 2020
7c3fe71
Handle close error in mongo plugin if not connected
bdentino Oct 29, 2020
29bafdc
Handle close error in mongo plugin if not connected
bdentino Oct 29, 2020
f33ae09
Update dependencis
bdentino Oct 29, 2020
e48155b
Update tests
bdentino Oct 29, 2020
3bd51a1
2.2.4
bdentino Oct 29, 2020
6dbe32a
Support LRU options in memory plugin
bdentino Feb 5, 2021
89c4c11
v2.3.0
bdentino Feb 5, 2021
8524444
Support configurable max/length function for memory plugin
bdentino Feb 21, 2021
837bd40
2.4.0
bdentino Feb 21, 2021
9643764
memoize child caches for better performance
bdentino Feb 22, 2021
25d5721
2.4.1
bdentino Feb 22, 2021
324d3fb
Improve redis set error handling
bdentino Feb 24, 2021
c3c8156
2.4.2
bdentino Feb 24, 2021
e78b7d6
Fix redis set stream
bdentino Mar 5, 2021
1dff9a9
Update history
bdentino Mar 5, 2021
678332e
2.4.3
bdentino Mar 5, 2021
1cd60a3
Add migration script
bdentino Mar 26, 2021
71eaa06
Add migration script
bdentino Mar 26, 2021
e7cc804
Update packages
bdentino Apr 8, 2021
cf19a79
2.4.4
bdentino Apr 8, 2021
b24cd02
Update mongo url support
bdentino Oct 12, 2021
cb20a88
v2.4.4
bdentino Oct 12, 2021
5212b01
Update mongo driver
bdentino Nov 15, 2021
8853b7b
2.5.0
bdentino Nov 15, 2021
f853e0e
Fix test env
bdentino Aug 6, 2024
2485f3f
PRO-2680 Aerospike client & tests
Ivan-Ratkin Aug 27, 2024
7c8026a
PR fixes
Ivan-Ratkin Sep 20, 2024
3ed9849
Let Kev work with aerospike and 14 version of node
Ivan-Ratkin Oct 9, 2024
ec86216
added Aerospike as peer dependency
Ivan-Ratkin Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
.nvmrc
.gitignore
.git/

20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
browser: false,
commonjs: true,
es6: true
},
extends: [ 'plugin:jest/recommended', 'standard' ],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018
},
plugins: [ 'jest' ],
rules: {
camelcase: 'off',
'array-bracket-spacing': [ 'error', 'always' ]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ node_modules
.lock-wscript

test/db
benchmarks
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
save-exact=true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.16.0
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM debian:latest

RUN apt-get update && \
apt-get install -y curl xz-utils && \
curl -fsSL https://nodejs.org/dist/v14.16.0/node-v14.16.0-linux-x64.tar.xz -o node.tar.xz && \
tar -xf node.tar.xz -C /usr/local --strip-components=1 && \
rm node.tar.xz && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

ENV PATH=$PATH:/usr/src/node_modules/.bin
ARG NODE_ENV=test

# Install app
ENV NODE_ENV=$NODE_ENV
ENV NODE_PATH=/usr/src/kev
ADD package.json package-lock.json /tmp/
RUN cd /tmp && \
# npm cache clean --force && \
npm install && \
rm -rf /root/.npm && \
mkdir -p /usr/src/kev && \
ln -sf /tmp/node_modules /usr/src/kev/node_modules && \
ln -sf /tmp/package.json /usr/src/kev/package.json

# Add source
WORKDIR /usr/src/kev
COPY .npmrc /usr/src/kev/.npmrc
COPY src /usr/src/kev/src

ENTRYPOINT [ "npm", "run" ]

# Default command
CMD [ "test" ]
102 changes: 102 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,106 @@

2.4.4 / 2021-10-12
==================

* Mongo+srv url support

2.4.3 / 2021-03-04
==================

* Fix redis set stream

2.3.0 / 2021-02-05
==================

* Support LRU options in memory plugin

2.1.5 / 2020-06-12
==================

* Fix mongo connection bug


2.1.4 / 2020-05-28
==================

* Do not call connect on connecting mongo client

2.1.3 / 2020-05-27
==================

* improve performance of memory tags
* Update performance tests

2.1.2 / 2020-05-20
==================

* Expose plugin and switch to native mongo driver

2.1.1 / 2020-05-19
==================

* Fix custom retrieval ttl = 0
* Fix tags when no prefixes provided

2.1.0 / 2020-05-19
==================

* Add rtl option to retrieval

2.0.0 / 2020-05-19
==================

* Support custom ttl on get

1.3.2 / 2019-09-29
==================

* Detect mongo session support

1.3.1 / 2019-09-29
==================

* Fix race condition on mongo collection verification

1.3.0 / 2019-09-29
==================

* Add tests for mongo replset
* Support for mongodb when transactions are not available

1.2.2 / 2019-09-29
==================

* Fix mongo deprecation warnings

1.2.1 / 2019-09-29
==================

* Ensure mongo collection is created before writing

1.2.0 / 2019-09-28
==================

* Update mongo driver and allow user to provide mongo client

1.1.0 / 2019-08-18
==================

* Add v8 serialization for improved performance

1.0.1 / 2019-06-13
==================

* Queue close until next tick

1.0.0 / 2019-06-06
==================
* Transition to docker/jest dev environment
* Rewrite API for async
* Support atomic transactions in mongo/redis
* Dataloaders for batching get/set/del requests
* Support for child buckets using kev.withPrefix('child')

0.6.8 / 2017-02-21
==================

Expand Down
46 changes: 27 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
test: test-memory test-mongo test-redis
SHELL := /bin/bash

test-memory:
@LOG=*test* ./node_modules/.bin/prok \
--env test/env.test \
--procfile test/memory/Procfile.memory \
--root .
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_REPO := $(shell git remote -v | grep origin | grep "(fetch)" | awk '{ print $$2 }')
GIT_DIRTY := $(shell git status --porcelain | wc -l)
GIT_DIRTY := $(shell if [[ "$(GIT_DIRTY)" -gt "0" ]]; then echo "yes"; else echo "no"; fi)

test-mongo:
@LOG=*test* ./node_modules/.bin/prok \
--env test/env.test \
--procfile test/mongo/Procfile.mongo \
--root .
VERSION := $(shell git describe --abbrev=0)
VERSION_DIRTY := $(shell git log --pretty=format:%h $(VERSION)..HEAD | wc -w | tr -d ' ')

test-redis:
@LOG=*test* ./node_modules/.bin/prok \
--env test/env.test \
--procfile test/redis/Procfile.redis \
--root .
BUILD_COMMIT := $(shell if [[ "$(GIT_DIRTY)" == "yes" ]]; then echo $(GIT_COMMIT)+dev; else echo $(GIT_COMMIT); fi)
BUILD_COMMIT := $(shell echo $(BUILD_COMMIT) | cut -c1-12)
BUILD_VERSION := $(shell if [[ "$(VERSION_DIRTY)" -gt "0" ]]; then echo "$(VERSION)-$(BUILD_COMMIT)"; else echo $(VERSION); fi)
BUILD_VERSION := $(shell if [[ "$(VERSION_DIRTY)" -gt "0" ]] || [[ "$(GIT_DIRTY)" == "yes" ]]; then echo "$(BUILD_VERSION)-dev"; else echo $(BUILD_VERSION); fi)
BUILD_VERSION := $(shell if [[ "$(GIT_BRANCH)" != "master" ]]; then echo $(GIT_BRANCH)-$(BUILD_VERSION) | tr '/' '-'; else echo $(BUILD_VERSION); fi)

install:
@npm install
LOCAL_COMPOSE := $(shell [ -f "docker-compose.local.yml" ] && echo "-f docker-compose.local.yml")
COMPOSE_FILES := $(shell echo "-f docker-compose.yml $(LOCAL_COMPOSE)")

.PHONY: test test-memory test-mongo test-redis
info:
@echo "git branch: $(GIT_BRANCH)"
@echo "git commit: $(GIT_COMMIT)"
@echo "git repo: $(GIT_REPO)"
@echo "git dirty: $(GIT_DIRTY)"
@echo "version: $(VERSION)"
@echo "commits since: $(VERSION_DIRTY)"
@echo "build commit: $(BUILD_COMMIT)"
@echo "build version: $(BUILD_VERSION)"

dc.files:
@echo $(COMPOSE_FILES)
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ Like a metronome counting off 10,000 brain cells per minute, Kev bangs his head

But Kev's pity party is short-lived. "Fool me twice...," he mutters under his breath, accepting responsibility for the path of shortsightedness that led him to this cleverly disguised opportunity. He's finally acknowledged the possibility (nay, probability) that he will need to swap his backend again at some point. Even if he doesn't, he shouldn't be relying on a particular storage engine if he wants to reuse any of these components in a different project. So his fingers hit the keys and like tiny little boxers punch out three simple functions:

```get(key, callback)```
```async get(key)```

```set(key, value[, callback])```
```async set(key, value[, { tags, ttl }])```

```del(key[, callback])```
```async del(key)```

So far so good. Kev writes a basic in-memory adapter and sets up the simplest conceivable test as a sanity check. It passes! Convinced he is on to something, Kev hastily refactors his project to use this new API and gives it a spin.

```var settings = Kev()```

His console explodes in a flurry of incomprehensible stack traces. A brief moment of panic ensues before Kev realizes that his application is simply expecting data that still lives in Redis. He whips up an adapter and with a single-line change reconnects his project to its old storage backend.

```var settings = Kev({ store: KevRedis( { port: process.env.REDIS_PORT } ) })```
```var settings = Kev({ url: process.env.REDIS_URL })```

It works! Kev's hands clench into fists and fly above his head in a celebratory spasm just awkward enough to expose a man whose encounters with success must be infrequent at best. But there is no time for victory dances; the moment of truth has arrived. Kev still needs out-of-memory persistence and already has a remote mongo store setup that he can use. He quickly pulls together a MongoDB adapter and writes a simple script (using his new API) to populate his new instance with the data from Redis. One more single-line change and Kev's project is using MongoDB instead of Redis.

```var settings = Kev({ store: KevMongo( { url: process.env.MONGO_URL } ) })```
```var settings = Kev({ url: process.env.MONGO_URL })```

Kev is ecstatic. Where against a wall a head once beat in despair, a heart now beats in excitement. The skies have opened up and Kev has seen the light. Never again will his time be wasted on meaningless refactoring efforts. Never again will his settings, his caches, his packages, his *life* be bound to a particular persistence layer. He is free, and so are we.

Expand All @@ -47,14 +47,13 @@ You see, I am Kev. You are Kev. We are all Kev, living in fear of trading speed

## Epilogue
There is, of course, still work to do. Kev plans to implement the following features as the need arises:
- Prefixed namespaces
- Atomic operations
- Batch puts/dels (adapter-specific)
- LevelDB adapter
- Streams
- Glob-matching keys
- [x] Prefixed namespaces
- [x] Atomic operations
- [x] Update batching
- [x] Glob-matching keys
- [x] Key streams
- [x] At-rest compression
- [ ] LevelDB adapter

## Getting Kev
```npm install kev```

Mongo and Redis are listed as dev dependencies to keep the footprint light. If you're using one of them for your storage layer, make sure you add it to your project's package.json independently.
4 changes: 4 additions & 0 deletions db/mongo/init-rs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rs.initiate({
_id: 'repl',
members: [ { _id: 0, host: 'localhost:27017' } ]
})
67 changes: 67 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: "3"

volumes:
mongo-init: {}
mongo-rsinit: {}

services:
test:
build:
context: .
args:
NODE_ENV: test
platform: linux/amd64
command: test
volumes:
- ./src:/usr/src/kev/src
- ./benchmarks:/usr/src/kev/benchmarks
links:
- redis
- mongo_standalone
- mongo_replset
environment:
REDIS_URL: redis://redis:6379
MONGO_URL: mongodb://mongo_standalone:27017/test?retryWrites=false
MONGO_RS_URL: mongodb://mongo_replset:27017/test?replicaSet=repl
AEROSPIKE_URL: aerospike://aerospikedb:3000
depends_on:
aerospikedb:
condition: service_healthy
redis:
image: redis:alpine
mongo_standalone:
image: mongo:4.2
depends_on:
- mongo-init
volumes:
- mongo-init:/opt/mongo-init
hostname: mongo_standalone
entrypoint: /opt/mongo-init/bin/entrypoint.sh
environment:
MONGO_STORAGE_ENGINE: ephemeralForTest
mongo-init:
image: finboxio/mongo-init:v0.2.0
volumes:
- mongo-init:/opt/mongo-init

mongo_replset:
image: mongo:4.2
depends_on:
- mongo-rsinit
volumes:
- mongo-rsinit:/opt/mongo-init
hostname: mongo_replset
entrypoint: /opt/mongo-init/bin/entrypoint.sh
environment:
MONGO_REPLSET: repl
MONGO_ROLE: primary
mongo-rsinit:
image: finboxio/mongo-init:v0.2.0
volumes:
- mongo-rsinit:/opt/mongo-init
aerospikedb:
image: aerospike/aerospike-server:7.1
healthcheck:
test: /bin/asinfo -v status
ports:
- "3000:3000"
Loading