From 4ebc3264b4573b180ea160f65215e15bd2f28859 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 9 Apr 2022 22:58:54 +0100 Subject: [PATCH] Handle SIGINT and add pebble as the db --- demo/000010.log | Bin 0 -> 11 bytes demo/CURRENT | 1 + demo/LOCK | 0 demo/MANIFEST-000008 | Bin 0 -> 52 bytes demo/MANIFEST-000011 | Bin 0 -> 52 bytes demo/OPTIONS-000012 | 44 +++++++ go.mod | 15 +++ go.sum | 267 +++++++++++++++++++++++++++++++++++++++++++ orion.go | 20 +++- pkg/core/core.go | 24 +++- pkg/core/db.go | 54 +++++++++ 11 files changed, 419 insertions(+), 6 deletions(-) create mode 100644 demo/000010.log create mode 100644 demo/CURRENT create mode 100644 demo/LOCK create mode 100644 demo/MANIFEST-000008 create mode 100644 demo/MANIFEST-000011 create mode 100644 demo/OPTIONS-000012 create mode 100644 pkg/core/db.go diff --git a/demo/000010.log b/demo/000010.log new file mode 100644 index 0000000000000000000000000000000000000000..3cfd732a91227e463a8f342470ee3eebbbb558f6 GIT binary patch literal 11 OcmZQz00CBRAOQdXPyi7C literal 0 HcmV?d00001 diff --git a/demo/CURRENT b/demo/CURRENT new file mode 100644 index 0000000..5b54010 --- /dev/null +++ b/demo/CURRENT @@ -0,0 +1 @@ +MANIFEST-000011 diff --git a/demo/LOCK b/demo/LOCK new file mode 100644 index 0000000..e69de29 diff --git a/demo/MANIFEST-000008 b/demo/MANIFEST-000008 new file mode 100644 index 0000000000000000000000000000000000000000..8d2d191c5d78a131bb9887b0dcefd597d7806bc3 GIT binary patch literal 52 zcmZ4ZV6UqZ10$nUPHI_dPD+xVQ)NkNd1i5{bAE0?Vo_pAei0K3Gbal}?w + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +package core + +import "github.com/cockroachdb/pebble" + + +type DB struct { + conn *pebble.DB +} + +func CreateDB(path *string) (*DB, error){ + conn, err := pebble.Open("demo", &pebble.Options{}) + if err != nil { + return nil, err + } + + return &DB{ + conn, + }, nil +} + + +func (db *DB) Set(key *string, value *[]byte) error { + // Because of our use case we will only use string keys/values + return db.conn.Set([]byte(*key), *value, pebble.Sync) +} + +func (db *DB) Get(key *string) (*[]byte, error) { + value, closer, err := db.conn.Get([]byte(*key)) + if err != nil { + return nil, err + } + defer closer.Close() + + return &value, nil +} + +func (db *DB) Close(){ + db.conn.Close() +}