Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 6666e77

Browse files
committed
Add interactive example
1 parent 094bc84 commit 6666e77

5 files changed

Lines changed: 87 additions & 11 deletions

File tree

examples/interactive_example.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2021, Intel Corporation
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions
5+
# are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
#
10+
# * Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in
12+
# the documentation and/or other materials provided with the
13+
# distribution.
14+
#
15+
# * Neither the name of the copyright holder nor the names of its
16+
# contributors may be used to endorse or promote products derived
17+
# from this software without specific prior written permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
31+
# Usage:
32+
# insert element: 'interactive_example.py --path path_to_db --insert key value'
33+
# lookup element: 'interactive_example.py --path path_to_db --lookup key'
34+
# print all elements: 'interactive_example.py --path path_to_db --iterate'
35+
36+
import pmemkv
37+
import argparse
38+
39+
def callback_kv(key, value):
40+
print("key: ", memoryview(key).tobytes().decode(), " value: ", memoryview(value).tobytes().decode())
41+
42+
def callback_v(value):
43+
print(memoryview(value).tobytes().decode())
44+
45+
parser = argparse.ArgumentParser()
46+
parser.add_argument('--path', help='Path to the database')
47+
48+
group = parser.add_mutually_exclusive_group(required=True)
49+
group.add_argument('--lookup', nargs=1, metavar=('key'),
50+
help='Print element with specified key')
51+
group.add_argument('--insert', nargs=2, metavar=('key', 'value'),
52+
help='Insert element with specified key and value')
53+
group.add_argument('--iterate', action='store_true',
54+
help='Print all elements)
55+
56+
args = parser.parse_args()
57+
58+
print("Configuring engine")
59+
config = {}
60+
config["path"] = args.path
61+
config["size"] = 10485760
62+
config["create_if_missing"] = 1
63+
64+
print(f"Starting engine with config: {config}")
65+
db = pmemkv.Database("cmap", config)
66+
67+
if args.lookup:
68+
db.get(args.lookup[0], callback_v)
69+
elif args.insert:
70+
db.put(args.insert[0], args.insert[1])
71+
elif args.iterate:
72+
db.get_all(callback_kv)
73+
74+
print("Stopping engine")
75+
db.stop()

utils/docker/images/Dockerfile.fedora-31

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2016-2020, Intel Corporation
2+
# Copyright 2016-2021, Intel Corporation
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -74,6 +74,7 @@ RUN dnf update -y \
7474
wget \
7575
which \
7676
python3-pip \
77+
libatomic \
7778
&& dnf clean all
7879

7980
RUN pip3 install pytest setuptools wheel

utils/docker/images/install-libpmemobj-cpp.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright 2019, Intel Corporation
3+
# Copyright 2019-2021, Intel Corporation
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions
@@ -40,8 +40,8 @@ set -e
4040
PREFIX=/usr
4141
PACKAGE_TYPE=$1
4242

43-
# master: Merge pull request #652 from ldorau/Create-separate-Docker-images-for-v1.10-branch
44-
LIBPMEMOBJ_CPP_VERSION="006137044243981f4760ae220101a43cf97bcf2d"
43+
# master: Merge pull request #1062 from igchor/fix_parallel_xexec
44+
LIBPMEMOBJ_CPP_VERSION='485353b9c2fdbaf57607dcd83551664cbc3cd963'
4545

4646
git clone https://github.com/pmem/libpmemobj-cpp --shallow-since=2019-10-02
4747
cd libpmemobj-cpp
@@ -50,7 +50,7 @@ git checkout $LIBPMEMOBJ_CPP_VERSION
5050
mkdir build
5151
cd build
5252

53-
cmake .. -DCPACK_GENERATOR="$PACKAGE_TYPE" -DCMAKE_INSTALL_PREFIX=$PREFIX
53+
cmake .. -DCPACK_GENERATOR="$PACKAGE_TYPE" -DCMAKE_INSTALL_PREFIX=$PREFIX -DTESTS_USE_VALGRIND=0
5454

5555
if [ "$PACKAGE_TYPE" = "" ]; then
5656
make -j$(nproc) install

utils/docker/images/install-pmdk.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright 2019, Intel Corporation
3+
# Copyright 2019-2021, Intel Corporation
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions
@@ -39,8 +39,8 @@ set -e
3939
PREFIX=/usr
4040
PACKAGE_TYPE=$1
4141

42-
# stable-1.8: common: fix build on GitHub Actions
43-
PMDK_VERSION="eeb8fd86c6c72f4607a22a1e9d9f7da31be8af2a"
42+
# 1.10
43+
PMDK_VERSION="b661e50ac7b2a6c6b153f1a52309a0e4149eb2a2"
4444

4545
git clone https://github.com/pmem/pmdk --shallow-since=2019-09-26
4646
cd pmdk

utils/docker/images/prepare-pmemkv.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright 2019, Intel Corporation
3+
# Copyright 2019-2021, Intel Corporation
44
#
55
# Redistribution and use in source and binary forms, with or without
66
# modification, are permitted provided that the following conditions
@@ -39,8 +39,8 @@ set -e
3939
PREFIX=/usr
4040
PACKAGE_TYPE=$1
4141

42-
# master: Merge pull request #602 from ldorau/Fix-setting-compilers--do-not-mix-gcc-with-clang
43-
current_pmemkv_version="5aff9f197e2e3eaae7f419c04ab9e2fc98309eed"
42+
# master: Merge pull request #985 from JanDorniak99/add_test_case_with_zero_filled_string
43+
current_pmemkv_version="e57429f4640278b7eead80f89832ba1136356c81"
4444
# stable-1.0: Merge pull request #528 from ldorau/Do-not-add-pmemkv_config...; 14.11.2019
4545
stable_1_pmemkv_version="a3735b5393f0d5411ef8a2468b36d2a1ed00c0a1"
4646
# stable-1.1: Version 1.1

0 commit comments

Comments
 (0)