Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2abe834
WIP
marcocapozzoli Jan 22, 2026
5b5bbbf
WIP - Add a simple test
marcocapozzoli Jan 22, 2026
e6f4e2b
WIP
marcocapozzoli Jan 26, 2026
e1ef57a
WIP
marcocapozzoli Jan 26, 2026
a29786d
WIP
marcocapozzoli Jan 27, 2026
db82fd8
WIP
marcocapozzoli Jan 27, 2026
8d82723
WIP
marcocapozzoli Jan 27, 2026
889167e
WIP
marcocapozzoli Jan 28, 2026
125c0b2
WIP
marcocapozzoli Jan 29, 2026
479638f
WIP
marcocapozzoli Jan 29, 2026
09dface
WIP
marcocapozzoli Jan 30, 2026
f00ec73
WIP
marcocapozzoli Jan 30, 2026
95292fb
WIP
marcocapozzoli Feb 2, 2026
d559a32
WIP
marcocapozzoli Feb 2, 2026
76ca880
WIP - doc
marcocapozzoli Feb 3, 2026
38906cb
WIP
marcocapozzoli Feb 3, 2026
73376df
WIP-tests
marcocapozzoli Feb 4, 2026
052de67
change log level
marcocapozzoli Feb 4, 2026
6cf4df6
add exists() in HandleTrie
marcocapozzoli Feb 5, 2026
4530a64
Merge branch 'master' into masc/1013-database-adapter-cpp
marcocapozzoli Feb 5, 2026
c7df9f1
Add ContextLoader
marcocapozzoli Feb 9, 2026
edf7523
adjust .json file
marcocapozzoli Feb 9, 2026
2050040
Add Processor
marcocapozzoli Feb 9, 2026
e9a695e
remove comments
marcocapozzoli Feb 9, 2026
769f70e
Add mutex
marcocapozzoli Feb 10, 2026
65f25ca
WIP - draft to pipeline
marcocapozzoli Feb 10, 2026
f84d677
WIP
marcocapozzoli Feb 10, 2026
2ee0457
WIP
marcocapozzoli Feb 10, 2026
3b40e65
WIP
marcocapozzoli Feb 11, 2026
19c1cdf
add ContextLoad class
marcocapozzoli Feb 11, 2026
6e52df8
Organize the code
marcocapozzoli Feb 12, 2026
68579f3
WIP
marcocapozzoli Feb 12, 2026
09f74db
WIP
marcocapozzoli Feb 12, 2026
0b6f184
Change the owner of the connection.
marcocapozzoli Feb 18, 2026
ebceb97
Wip Pipepline
marcocapozzoli Feb 18, 2026
92b222c
WIP
marcocapozzoli Feb 20, 2026
fa2617e
wip
marcocapozzoli Feb 20, 2026
50c3b78
WIP
marcocapozzoli Feb 20, 2026
2b76c30
wip
marcocapozzoli Feb 20, 2026
526fa55
WIP
marcocapozzoli Feb 20, 2026
8e24561
wip
marcocapozzoli Feb 20, 2026
7445f56
WIP - format_all
marcocapozzoli Feb 20, 2026
c42996c
remove logs
marcocapozzoli Feb 20, 2026
58acbb5
refactor: update logging levels and improve is_finished method implem…
marcocapozzoli Feb 20, 2026
e1d2cab
refactor: change log level from INFO to DEBUG in DatabaseMappingJob a…
marcocapozzoli Feb 20, 2026
28eb884
Merge branch 'masc/1013-database-adapter-cpp-2' into masc/1013-databa…
marcocapozzoli Feb 23, 2026
6e40de7
Add main file
marcocapozzoli Feb 24, 2026
a14eefd
Add log progress
marcocapozzoli Feb 24, 2026
49fdb81
refactor DatabaseConnection and Pipeline
marcocapozzoli Feb 27, 2026
85cefd0
Add database adapter functionality and refactor related components
marcocapozzoli Mar 2, 2026
8729772
Refactor AtomPersistenceJob to manage atom processing and logging mor…
marcocapozzoli Mar 3, 2026
cf0136d
Merge branch 'master' into masc/1013-database-adapter-cpp-3
marcocapozzoli Mar 3, 2026
234ac9a
apply lint
marcocapozzoli Mar 3, 2026
84a989f
fixed all bazel build/scripts, DAS docker image
levisingularity Mar 5, 2026
dbe3331
fix pipeline setup
levisingularity Mar 5, 2026
c561fce
Merge pull request #1053 from singnet/1013-build-scripts
marcocapozzoli Mar 5, 2026
2354876
Refactor PostgresWrapper to implement cursor-based fetching and updat…
marcocapozzoli Mar 5, 2026
1ddd36c
Add Postgres server setup to unit test workflow and improve resource …
marcocapozzoli Mar 6, 2026
39a15d6
Refactor DatabaseMappingJob destructor for improved readability
marcocapozzoli Mar 6, 2026
3a1a0af
Refactor DatabaseConnection destructor to avoid stopping connection o…
marcocapozzoli Mar 6, 2026
4741683
add waiting loop
marcocapozzoli Mar 6, 2026
28e4f2f
Merge branch 'master' into masc/1013-database-adapter-cpp-3
marcocapozzoli Mar 6, 2026
8ae296f
Refactor DataMapper to initialize empty_trie_value
marcocapozzoli Mar 6, 2026
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
57 changes: 45 additions & 12 deletions .docker/poc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,49 @@ RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then \
else \
LIB_SUBDIR="x86_64-linux-gnu"; \
fi \
&& mkdir -p ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR} ${DAS_DIR}/syslibs/lib/${LIB_SUBDIR} ${DAS_DIR}/syslibs/etc/ssl/certs \
&& cp -f /usr/lib/${LIB_SUBDIR}/libssl.so.3 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /usr/lib/${LIB_SUBDIR}/libcrypto.so.3 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /lib/${LIB_SUBDIR}/libz.so.1 ${DAS_DIR}/syslibs/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /usr/lib/${LIB_SUBDIR}/libzstd.so.1 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /usr/lib/${LIB_SUBDIR}/libsnappy.so.1 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /lib/${LIB_SUBDIR}/libbz2.so.1.0 ${DAS_DIR}/syslibs/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /lib/${LIB_SUBDIR}/liblzma.so.5 ${DAS_DIR}/syslibs/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /usr/lib/${LIB_SUBDIR}/libcurl.so.4 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& cp -f /usr/lib/${LIB_SUBDIR}/libevent-2.1.so.7 ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true \
&& mkdir -p ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR} \
${DAS_DIR}/syslibs/lib/${LIB_SUBDIR} \
${DAS_DIR}/syslibs/etc/ssl/certs \
# --- usr/lib/ libraries ---
&& USR_LIBS=" \
libssl.so.3 \
libcrypto.so.3 \
libzstd.so.1 \
libsnappy.so.1 \
libcurl.so.4 \
libevent-2.1.so.7 \
# Libs from here and on are related to the libpqxx lib, used by the database-adapter.
libgssapi_krb5.so.2 \
libkrb5.so.3 \
libk5crypto.so.3 \
libcom_err.so.2 \
libkrb5support.so.0 \
liblber-2.5.so.0 \
libkeyutils.so.1 \
libp11-kit.so.0 \
libidn2.so.0 \
libunistring.so.2 \
libtasn1.so.6 \
libnettle.so.8 \
libhogweed.so.6 \
libgmp.so.10 \
libffi.so.8 \
libldap-2.5.so.0 \
libsasl2.so.2 \
libgnutls.so.30 \
" \
# lib/ folder libraries ---
&& LIB_LIBS=" \
libz.so.1 \
libbz2.so.1.0 \
liblzma.so.5 \
" \
&& for lib in $USR_LIBS; do \
cp -f /usr/lib/${LIB_SUBDIR}/$lib ${DAS_DIR}/syslibs/usr/lib/${LIB_SUBDIR}/ 2>/dev/null || true; \
done \
&& for lib in $LIB_LIBS; do \
cp -f /lib/${LIB_SUBDIR}/$lib ${DAS_DIR}/syslibs/lib/${LIB_SUBDIR}/ 2>/dev/null || true; \
done \
&& cp -f /etc/ssl/certs/ca-certificates.crt ${DAS_DIR}/syslibs/etc/ssl/certs/ 2>/dev/null || true

FROM gcr.io/distroless/cc-debian12:nonroot AS runner
Expand All @@ -61,8 +94,8 @@ COPY --from=builder /opt/das/syslibs/usr/lib/ /usr/lib/
COPY --from=builder /opt/das/syslibs/lib/ /lib/
COPY --from=builder /opt/das/syslibs/etc/ssl/certs/ /etc/ssl/certs/

ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/aarch64-linux-gnu:/lib/x86_64-linux-gnu:/lib/aarch64-linux-gnu
ENV LD_LIBRARY_PATH=/opt/das/lib:/usr/local/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/aarch64-linux-gnu:/lib/x86_64-linux-gnu:/lib/aarch64-linux-gnu

USER nonroot:nonroot

CMD [ "query_broker" ]
CMD [ "busnode" ]
17 changes: 17 additions & 0 deletions .github/scripts/bazel_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ BAZEL_BINARY_TARGETS=(
"//:tests_db_loader"
"//:busnode"
"//:busclient"
"//:database_adapter"
)

BAZEL_BINARY_OUTPUTS=(
Expand All @@ -78,6 +79,7 @@ BAZEL_BINARY_OUTPUTS=(
"bazel-bin/tests_db_loader"
"bazel-bin/busnode"
"bazel-bin/busclient"
"bazel-bin/database_adapter"
)

BAZEL_LIB_OUTPUTS=(
Expand Down Expand Up @@ -181,6 +183,21 @@ if [ -d "$LIB_DIR" ]; then
done
fi

echo "[INFO] Copying database-adapter shared library dependencies into $LIB_DIR..."

find "$BIN_DIR" -type f -executable -name "database_adapter" | while IFS= read -r binfile; do
ldd "$binfile" | awk '/=> \// { print $3 }' | while IFS= read -r dep; do
dep_base=$(basename "$dep")
case "$dep_base" in
"libpq.so.5")
if [ -f "$dep" ]; then
cp -f "$dep" "$LIB_DIR"
fi
;;
esac
done
done

echo "[INFO] Build finished successfully."
echo "[INFO] Binaries in: $BIN_DIR"
echo "[INFO] Libraries in: $LIB_DIR"
Expand Down
26 changes: 25 additions & 1 deletion .github/scripts/setup_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ sudo apt update -y
sudo apt install -y \
git build-essential curl protobuf-compiler python3 python3-pip \
cmake unzip uuid-runtime lcov bc \
libevent-dev libssl-dev pkg-config libncurses5
libevent-dev libssl-dev pkg-config libncurses5 libpq-dev

echo "[INFO] Cleaning apt cache..."
sudo apt clean -y || true
sudo rm -rf /var/lib/apt/lists/* || true

# Installing bazelisk and copying other assets.

echo "[INFO] Installing 3rd-party tools (bazelisk, buildifier)..."

if [[ ! -f "${ASSETS_DIR}/3rd-party.tgz" ]]; then
Expand Down Expand Up @@ -119,6 +121,28 @@ if ! id "builder" &>/dev/null; then
sudo useradd -ms /bin/bash builder
fi

echo "[INFO] Installing libpqxx (PostgreSQL C++ client)..."

if [[ ! -f "${ASSETS_DIR}/libpqxx-7.10.5.tar.gz" ]]; then
echo "[ERROR] ${ASSETS_DIR}/libpqxx-7.10.5.tar.gz not found."
exit 1
fi

cp "${ASSETS_DIR}/libpqxx-7.10.5.tar.gz" "${TMP_DIR}/"
cd "${TMP_DIR}"
tar xzvf libpqxx-7.10.5.tar.gz
cd libpqxx-7.10.5

cmake -S . -B build \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTING=OFF \
-DCMAKE_INSTALL_PREFIX=/usr/local

cmake --build build -j"$(nproc)"

sudo cmake --install build
sudo ldconfig

echo "[INFO] Configuring git safe.directory for ${DAS_DIR}..."
sudo -u builder git config --global --add safe.directory "${DAS_DIR}"

Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,20 @@ jobs:
sleep 1
done

- name: Starting Postgres Server and load database
run: |-
docker run -d --name pg_test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=postgres_wrapper_test -p 5433:5432 postgres:15

for i in {1..30}; do
if docker exec pg_test pg_isready -U postgres -d postgres_wrapper_test; then
echo "Postgres is ready"
break
fi
echo "Waiting for Postgres..."
sleep 1
done

docker exec -i pg_test psql -U postgres -d postgres_wrapper_test < src/scripts/postgres_setup.sql

- name: Execute Unit Test Suite
run: make test-all
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ setup-inference-toy-problem:
run-tests-db-loader:
@bash -x src/scripts/run.sh tests_db_loader $(OPTIONS)

run-adapter:
@bash -x src/scripts/run.sh database_adapter $(OPTIONS)

setup-nunet-dms:
@bash -x src/scripts/setup-nunet-dms.sh

Expand Down
22 changes: 22 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cc_shared_library(
"//atomdb:atomdb_lib",
"//attention_broker:attention_broker_lib",
"//commons:commons_lib",
"//db_adapter:db_adapter_lib",
"//distributed_algorithm_node:distributed_algorithm_node_lib",
"//hasher:hasher_lib",
"//metta:metta_lib",
Expand Down Expand Up @@ -188,6 +189,27 @@ cc_binary(
],
)

cc_binary(
name = "database_adapter",
srcs = [],
defines = ["BAZEL_BUILD"],
linkopts = [
"-L/usr/local/lib",
"-lpqxx",
"-lpq",
"-lhiredis_cluster",
"-lhiredis",
"-lmongocxx",
"-lbsoncxx",
],
linkstatic = 1,
deps = [
"//commons:commons_lib",
"//tests/main:database_adapter_main_lib",
"@mbedtls",
],
)

cc_binary(
name = "busnode",
srcs = [],
Expand Down
Binary file added src/assets/libpqxx-7.10.5.tar.gz
Binary file not shown.
11 changes: 10 additions & 1 deletion src/commons/HandleTrie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ HandleTrie::TrieNode::~TrieNode() {
delete children[i];
}
delete[] children;
delete value;
// TODO: Remove this check once improve insert()
if (value != NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a TODO here so we can remove this check once we improve HandleTrie::insert() to not accept NULL as value

delete value;
value = NULL;
}
}

string HandleTrie::TrieValue::to_string() { return ""; }
Expand Down Expand Up @@ -269,3 +273,8 @@ void HandleTrie::traverse(bool keep_root_locked,
root->trie_node_mutex.unlock();
}
}

bool HandleTrie::exists(const string& key) {
TrieNode* node = lookup_node(key);
return node != NULL ? true : false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

return lookup_node(key) != NULL;

}
2 changes: 2 additions & 0 deletions src/commons/HandleTrie.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class HandleTrie {
*/
TrieValue* lookup(const string& key);

bool exists(const string& key);

/**
* Remove a key from this HandleTrie and its associated value.
*
Expand Down
96 changes: 96 additions & 0 deletions src/db_adapter/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "db_adapter_lib",
includes = ["."],
deps = [
":context_loader",
":data_mapper",
":data_types",
":database_connection",
":database_wrapper",
":pipeline",
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
"//db_adapter/postgres:postgres_lib",
],
)

cc_library(
name = "data_types",
hdrs = ["DataTypes.h"],
includes = ["."],
deps = [
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
],
)

cc_library(
name = "data_mapper",
srcs = ["DataMapper.cc"],
hdrs = ["DataMapper.h"],
includes = ["."],
deps = [
":data_types",
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
],
)

cc_library(
name = "database_wrapper",
srcs = ["DatabaseWrapper.cc"],
hdrs = ["DatabaseWrapper.h"],
includes = ["."],
deps = [
":data_mapper",
":data_types",
":database_connection",
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
],
)

cc_library(
name = "context_loader",
srcs = ["ContextLoader.cc"],
hdrs = ["ContextLoader.h"],
includes = ["."],
deps = [
":data_types",
"//commons:commons_lib",
"@nlohmann_json//:json",
],
)

cc_library(
name = "database_connection",
srcs = ["DatabaseConnection.cc"],
hdrs = ["DatabaseConnection.h"],
includes = ["."],
deps = [
":data_types",
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
"//commons/processor:processor_lib",
],
)

cc_library(
name = "pipeline",
srcs = ["Pipeline.cc"],
hdrs = ["Pipeline.h"],
includes = ["."],
deps = [
":data_types",
":database_wrapper",
"//atomdb",
"//atomdb:atomdb_singleton",
"//commons:commons_lib",
"//commons/atoms:atoms_lib",
"//db_adapter/postgres:postgres_lib",
],
)
Loading
Loading