diff --git a/installer/prereq.sh b/installer/prereq.sh index 39449a5..36f7ec9 100755 --- a/installer/prereq.sh +++ b/installer/prereq.sh @@ -200,16 +200,16 @@ tmpgrub=$tmp.tmp cp /etc/default/grub "$tmpgrub" updated=0 -# Check GRUB_CMDLINE_LINUX_DEFAULT exists, create new if not exists. +# Check GRUB_CMDLINE_LINUX exists, create new if not exists. # If exists check for cgroup_enable=memory and swapaccount=1 and configure them if not already configured. -sed -n -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{q100}" "$tmpgrub" +sed -n -r -e "/^GRUB_CMDLINE_LINUX=/{q100}" "$tmpgrub" res=$? if [ $res -eq 100 ]; then # Check cgroup_enable=memory exists, create new if not exists otherwise skip. - sed -n -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ /cgroup_enable=memory/{q100}; }" "$tmpgrub" + sed -n -r -e "/^GRUB_CMDLINE_LINUX=/{ /cgroup_enable=memory/{q100}; }" "$tmpgrub" res=$? if [ $res -eq 0 ]; then - sed -i -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ s/\"\s*\$/ cgroup_enable=memory\"/ }" "$tmpgrub" + sed -i -r -e "/^GRUB_CMDLINE_LINUX=/{ s/\"\s*\$/ cgroup_enable=memory\"/ }" "$tmpgrub" res=$? updated=1 fi @@ -217,32 +217,32 @@ if [ $res -eq 100 ]; then # If there's no error. if [ $res -eq 0 ] || [ $res -eq 100 ]; then # Check swapaccount=1 exists, create new if not exists otherwise skip. - sed -n -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ /swapaccount=1/{q100}; }" "$tmpgrub" + sed -n -r -e "/^GRUB_CMDLINE_LINUX=/{ /swapaccount=1/{q100}; }" "$tmpgrub" res=$? if [ $res -eq 0 ]; then # Check whether there's swapaccount value other than 1, If so replace value with 1. # Otherwise add swapaccount=1 after cgroup_enable=memory. - sed -n -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ /swapaccount=/{q100}; }" "$tmpgrub" + sed -n -r -e "/^GRUB_CMDLINE_LINUX=/{ /swapaccount=/{q100}; }" "$tmpgrub" res=$? if [ $res -eq 100 ]; then - sed -i -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ s/swapaccount=[0-9]*/swapaccount=1/ }" "$tmpgrub" + sed -i -r -e "/^GRUB_CMDLINE_LINUX=/{ s/swapaccount=[0-9]*/swapaccount=1/ }" "$tmpgrub" res=$? updated=1 elif [ $res -eq 0 ]; then - sed -i -r -e "/^GRUB_CMDLINE_LINUX_DEFAULT=/{ s/cgroup_enable=memory/cgroup_enable=memory swapaccount=1/ }" "$tmpgrub" + sed -i -r -e "/^GRUB_CMDLINE_LINUX=/{ s/cgroup_enable=memory/cgroup_enable=memory swapaccount=1/ }" "$tmpgrub" res=$? updated=1 fi fi fi elif [ $res -eq 0 ]; then - echo "GRUB_CMDLINE_LINUX_DEFAULT=\"cgroup_enable=memory swapaccount=1\"" >> "$tmpgrub" + echo "GRUB_CMDLINE_LINUX=\"cgroup_enable=memory swapaccount=1\"" >> "$tmpgrub" res=$? updated=1 fi # If the res is not success(0) or alredy exist(100). -[ ! $res -eq 0 ] && [ ! $res -eq 100 ] && echo "Grub GRUB_CMDLINE_LINUX_DEFAULT update failed." && exit 1 +[ ! $res -eq 0 ] && [ ! $res -eq 100 ] && echo "Grub GRUB_CMDLINE_LINUX update failed." && exit 1 # If updated we do update-grub and reboot. if [ $updated -eq 1 ]; then diff --git a/installer/sashimono-install.sh b/installer/sashimono-install.sh index c1daf3e..96d4aca 100755 --- a/installer/sashimono-install.sh +++ b/installer/sashimono-install.sh @@ -171,6 +171,10 @@ else ! $SASHIMONO_BIN/sagent new $SASHIMONO_DATA $inetaddr $inst_count $cpuMicroSec $ramKB $swapKB $diskKB && rollback fi +if [[ "$NO_MB" == "" && -f $MB_XRPL_DATA/mb-xrpl.cfg ]]; then + ! sudo -u "$MB_XRPL_USER" MB_DATA_DIR="$MB_XRPL_DATA" node "$MB_XRPL_BIN" upgrade && rollback +fi + # Install Sashimono Agent systemd service. # StartLimitIntervalSec=0 to make unlimited retries. RestartSec=5 is to keep 5 second gap between restarts. echo "[Unit] diff --git a/installer/setup.sh b/installer/setup.sh index 13c9c71..2c9409a 100755 --- a/installer/setup.sh +++ b/installer/setup.sh @@ -486,7 +486,7 @@ function check_installer_pending_finish() { function reg_info() { echo "" - if sudo -u $MB_XRPL_USER MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN reginfo ; then + if MB_DATA_DIR=$MB_XRPL_DATA node $MB_XRPL_BIN reginfo ; then echo -e "\nYour account details are stored in $MB_XRPL_DATA/mb-xrpl.cfg and $MB_XRPL_DATA/secret.cfg." fi } @@ -521,6 +521,12 @@ if [ "$mode" == "install" ]; then check_sys_req + # Check bc command is installed. + if ! command -v bc &>/dev/null; then + echo "bc command not found. Installing.." + apt-get -y install bc >/dev/null + fi + # Display licence file and ask for concent. printf "\n*****************************************************************************************************\n\n" curl --silent $licence_url | cat @@ -545,7 +551,9 @@ if [ "$mode" == "install" ]; then echo -e "Using allocation $(GB $alloc_ramKB) RAM, $(GB $alloc_swapKB) Swap, $(GB $alloc_diskKB) disk space, $alloc_instcount contract instances.\n" set_lease_amount - (( $(echo "$lease_amount > 0" |bc -l) )) && echo -e "Using lease amount $lease_amount EVRs.\n" || echo -e "Using anchor tenant target price as lease amount.\n" + # Commented for future consideration. + # (( $(echo "$lease_amount > 0" |bc -l) )) && echo -e "Using lease amount $lease_amount EVRs.\n" || echo -e "Using anchor tenant target price as lease amount.\n" + (( $(echo "$lease_amount > 0" |bc -l) )) && echo -e "Using lease amount $lease_amount EVRs.\n" echo "Starting installation..." install_evernode 0 diff --git a/mb-xrpl/lib/appenv.js b/mb-xrpl/lib/appenv.js index bdf5d3c..48173e2 100644 --- a/mb-xrpl/lib/appenv.js +++ b/mb-xrpl/lib/appenv.js @@ -19,7 +19,7 @@ appenv = { ACQUIRE_LEASE_TIMEOUT_THRESHOLD: 0.8, ACQUIRE_LEASE_WAIT_TIMEOUT_THRESHOLD: 0.4, SASHI_CLI_PATH: appenv.IS_DEV_MODE ? "../build/sashi" : "/usr/bin/sashi", - MB_VERSION: '0.0.5', + MB_VERSION: '0.5.0', TOS_HASH: 'BECF974A2C48C21F39046C1121E5DF7BD55648E1005172868CD5738C23E3C073' } Object.freeze(appenv); diff --git a/mb-xrpl/lib/config-helper.js b/mb-xrpl/lib/config-helper.js index 28830c4..2465981 100644 --- a/mb-xrpl/lib/config-helper.js +++ b/mb-xrpl/lib/config-helper.js @@ -1,15 +1,19 @@ const fs = require('fs'); class ConfigHelper { - static readConfig(configPath, secretConfigPath) { + static readConfig(configPath, secretConfigPath = null) { if (!fs.existsSync(configPath)) throw `Config file does not exist at ${configPath}`; - else if (!fs.existsSync(secretConfigPath)) - throw `Secret config file does not exist at ${secretConfigPath}`; let config = JSON.parse(fs.readFileSync(configPath).toString()); - const secretCfg = JSON.parse(fs.readFileSync(secretConfigPath).toString()); - config.xrpl = { ...config.xrpl, ...secretCfg.xrpl }; + + if (secretConfigPath) { + if (!fs.existsSync(secretConfigPath)) + throw `Secret config file does not exist at ${secretConfigPath}`; + + const secretCfg = JSON.parse(fs.readFileSync(secretConfigPath).toString()); + config.xrpl = { ...config.xrpl, ...secretCfg.xrpl }; + } // Validate lease amount. if (config.xrpl.leaseAmount && typeof config.xrpl.leaseAmount === 'string') { diff --git a/mb-xrpl/lib/message-board.js b/mb-xrpl/lib/message-board.js index 07e179e..0ab9c00 100644 --- a/mb-xrpl/lib/message-board.js +++ b/mb-xrpl/lib/message-board.js @@ -69,7 +69,7 @@ class MessageBoard { this.activeInstanceCount = leaseRecords.length; console.log(`Active instance count: ${this.activeInstanceCount}`); // Update the registry with the active instance count. - await this.hostClient.updateRegInfo(this.activeInstanceCount); + await this.hostClient.updateRegInfo(this.activeInstanceCount, this.cfg.version); this.db.close(); // Check for instance expiry. @@ -113,7 +113,14 @@ class MessageBoard { await this.destroyInstance(x.containerName, x.tenant, uriInfo.leaseIndex, true); this.activeInstanceCount--; await this.hostClient.updateRegInfo(this.activeInstanceCount); - await this.updateLeaseStatus(x.txHash, LeaseStatus.EXPIRED); + + /** + * Soft deletion for debugging purpose. + */ + // await this.updateLeaseStatus(x.txHash, LeaseStatus.EXPIRED); + + // Delete the lease record related to this instance (Permanent Delete). + await this.deleteLeaseRecord(x.txHash); console.log(`Destroyed ${x.containerName}`); } catch (e) { @@ -421,6 +428,10 @@ class MessageBoard { await this.db.updateValue(this.leaseTable, savingData, { tx_hash: txHash }); } + async deleteLeaseRecord(txHash) { + await this.db.deleteValues(this.leaseTable, { tx_hash: txHash }); + } + getExpiryLedger(ledgerIndex, moments) { return ledgerIndex + moments * this.hostClient.config.momentSize; } diff --git a/mb-xrpl/lib/setup.js b/mb-xrpl/lib/setup.js index d55830f..71ca7bb 100644 --- a/mb-xrpl/lib/setup.js +++ b/mb-xrpl/lib/setup.js @@ -38,8 +38,8 @@ class Setup { }; } - #getConfig() { - return ConfigHelper.readConfig(appenv.CONFIG_PATH, appenv.SECRET_CONFIG_PATH); + #getConfig(readSecret = true) { + return ConfigHelper.readConfig(appenv.CONFIG_PATH, readSecret? appenv.SECRET_CONFIG_PATH : null); } #saveConfig(cfg) { @@ -174,7 +174,7 @@ class Setup { } async regInfo(isBasic) { - const acc = this.#getConfig().xrpl; + const acc = this.#getConfig(false).xrpl; console.log(`Registry address: ${acc.registryAddress}`); console.log(`Host account address: ${acc.address}`); @@ -184,7 +184,7 @@ class Setup { }); try { - const hostClient = new evernode.HostClient(acc.address, acc.secret); + const hostClient = new evernode.HostClient(acc.address); await hostClient.connect(); const [evrBalance, hostInfo] = await Promise.all([hostClient.getEVRBalance(), hostClient.getRegistration()]); diff --git a/mb-xrpl/lib/sqlite-handler.js b/mb-xrpl/lib/sqlite-handler.js index fb8188b..d4722c0 100644 --- a/mb-xrpl/lib/sqlite-handler.js +++ b/mb-xrpl/lib/sqlite-handler.js @@ -164,6 +164,25 @@ class SqliteDatabase { } } + async deleteValues(tableName, filter = null) { + if (!this.db) + throw 'Database connection is not open.'; + + let values = []; + let filterStr = '1 AND ' + if (filter) { + const columnNames = Object.keys(filter); + for (const columnName of columnNames) { + filterStr += `${columnName} = ? AND `; + values.push(filter[columnName] ? filter[columnName] : 'NULL'); + } + } + filterStr = filterStr.slice(0, -5); + + const query = `DELETE FROM ${tableName} WHERE ${filterStr};`; + return (await this.runQuery(query, values)); + } + runQuery(query, params = null) { return new Promise((resolve, reject) => { this.db.run(query, params ? params : [], function (err) { diff --git a/mb-xrpl/package-lock.json b/mb-xrpl/package-lock.json index 4053ae3..ec26c32 100644 --- a/mb-xrpl/package-lock.json +++ b/mb-xrpl/package-lock.json @@ -573,16 +573,18 @@ } }, "es-abstract": { - "version": "1.19.5", - "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.19.5.tgz", - "integrity": "sha512-Aa2G2+Rd3b6kxEUKTF4TaW67czBLyAv3z7VOhYRU50YBx+bbsYZ9xQP4lMNazePuFlybXI0V4MruPos7qUo5fA==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.0.tgz", + "integrity": "sha512-URbD8tgRthKD3YcC39vbvSDrX23upXnPcnGAjQfgxXF5ID75YcENawc9ZX/9iTP9ptUyfCLIxTTuMYoRfiOVKA==", "requires": { "call-bind": "^1.0.2", "es-to-primitive": "^1.2.1", "function-bind": "^1.1.1", + "function.prototype.name": "^1.1.5", "get-intrinsic": "^1.1.1", "get-symbol-description": "^1.0.0", "has": "^1.0.3", + "has-property-descriptors": "^1.0.0", "has-symbols": "^1.0.3", "internal-slot": "^1.0.3", "is-callable": "^1.2.4", @@ -594,9 +596,10 @@ "object-inspect": "^1.12.0", "object-keys": "^1.1.1", "object.assign": "^4.1.2", - "string.prototype.trimend": "^1.0.4", - "string.prototype.trimstart": "^1.0.4", - "unbox-primitive": "^1.0.1" + "regexp.prototype.flags": "^1.4.1", + "string.prototype.trimend": "^1.0.5", + "string.prototype.trimstart": "^1.0.5", + "unbox-primitive": "^1.0.2" } }, "es-to-primitive": { @@ -773,9 +776,9 @@ "dev": true }, "evernode-js-client": { - "version": "0.4.30", - "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.4.30.tgz", - "integrity": "sha512-MIkBuARgOb8xnomTviStG2W6M1hV/vQtI7iNnqehC3IgG8FKToqeSvZ43PplhL1iv236Exq5fD9+0puCgoOSoQ==", + "version": "0.4.31", + "resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.4.31.tgz", + "integrity": "sha512-jFs7G1dkQamQ3jKehoP+d+NWEok+ELsukJDY+IZyiViI/XZaTbAN+anOL0194NGVKRmC3RztDcYYKYaxeakhtw==", "requires": { "elliptic": "6.5.4", "ripple-address-codec": "4.2.0", @@ -904,12 +907,28 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, + "function.prototype.name": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.5.tgz", + "integrity": "sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==", + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.0", + "functions-have-names": "^1.2.2" + } + }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==" + }, "gauge": { "version": "2.7.4", "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", @@ -1834,6 +1853,16 @@ "util-deprecate": "^1.0.1" } }, + "regexp.prototype.flags": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", + "integrity": "sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==", + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "functions-have-names": "^1.2.2" + } + }, "regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -2045,21 +2074,23 @@ } }, "string.prototype.trimend": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.4.tgz", - "integrity": "sha512-y9xCjw1P23Awk8EvTpcyL2NIr1j7wJ39f+k6lvRnSMz+mz9CGz9NYPelDk42kOz6+ql8xjfK8oYzy3jAP5QU5A==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", + "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", "requires": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" } }, "string.prototype.trimstart": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.4.tgz", - "integrity": "sha512-jh6e984OBfvxS50tdY2nRZnoC5/mLFKOREQfw8t5yytkoUsJRNxvI/E39qu1sD0OtWI3OC0XgKSmcWwziwYuZw==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", + "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", "requires": { "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" } }, "string_decoder": { @@ -2288,9 +2319,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", - "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==" + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz", + "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==" }, "xrpl": { "version": "2.2.1", @@ -2323,15 +2354,15 @@ } }, "ripple-keypairs": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/ripple-keypairs/-/ripple-keypairs-1.1.3.tgz", - "integrity": "sha512-y74Y3c0g652BgpDhWsf0x98GnUyY2D9eO2ay2exienUfbIe00TeIiFhYXQhCGVnliGsxeV9WTpU+YuEWuIxuhw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/ripple-keypairs/-/ripple-keypairs-1.1.4.tgz", + "integrity": "sha512-PMMjTOxZmCSBOvHPj6bA+V/HGx7oFgDtGGI8VcZYuaFO2H87UX0X0jhfHy+LA2Xy31WYlD7GaDIDDt2QO+AMtw==", "requires": { "bn.js": "^5.1.1", "brorand": "^1.0.5", "elliptic": "^6.5.4", "hash.js": "^1.0.3", - "ripple-address-codec": "^4.2.3" + "ripple-address-codec": "^4.2.4" } } } diff --git a/mb-xrpl/package.json b/mb-xrpl/package.json index 9aaaa15..7bf1835 100644 --- a/mb-xrpl/package.json +++ b/mb-xrpl/package.json @@ -5,7 +5,7 @@ "build": "npm run lint && ncc build app.js --minify -o dist" }, "dependencies": { - "evernode-js-client": "0.4.30", + "evernode-js-client": "0.4.31", "sqlite3": "5.0.2" }, "devDependencies": { diff --git a/src/hp_manager.cpp b/src/hp_manager.cpp index 822874d..6237098 100644 --- a/src/hp_manager.cpp +++ b/src/hp_manager.cpp @@ -453,7 +453,8 @@ namespace hp LOG_INFO << "Destroying container " << container_name; if (docker_remove(info.username, container_name) == -1 || - sqlite::update_status_in_container(db, container_name, CONTAINER_STATES[STATES::DESTROYED]) == -1) + // sqlite::update_status_in_container(db, container_name, CONTAINER_STATES[STATES::DESTROYED]) == -1) // Soft Deletion. + sqlite::delete_hp_instance(db, container_name) == -1) // Permanent Deletion. { LOG_ERROR << errno << ": Error destroying container " << container_name; return -1; diff --git a/src/sqlite.cpp b/src/sqlite.cpp index 72ffb36..22b5222 100644 --- a/src/sqlite.cpp +++ b/src/sqlite.cpp @@ -45,6 +45,8 @@ namespace sqlite constexpr const char *IS_TABLE_EXISTS = "SELECT * FROM sqlite_master WHERE type='table' AND name = ?"; + constexpr const char *DELETE_HP_INSTANCE = "DELETE FROM instances WHERE name = ?"; + // Message boad database queries constexpr const char *GET_LEASES_LIST = "SELECT timestamp, tx_hash, tenant_xrp_address, life_moments, container_name, created_on_ledger, status FROM leases WHERE status = 'Acquired' OR status = 'Extended'"; @@ -593,4 +595,24 @@ namespace sqlite sqlite3_finalize(stmt); return -1; } + + /** + * Delete an instance record based on the provided container name. + * @param db Database connection. + * @param container_name Name of the container which should be deleted. + * @return 0 on success and -1 on error. + */ + int delete_hp_instance(sqlite3 *db, std::string_view container_name) + { + sqlite3_stmt *stmt; + if (sqlite3_prepare_v2(db, DELETE_HP_INSTANCE, -1, &stmt, 0) == SQLITE_OK && stmt != NULL && + sqlite3_bind_text(stmt, 1, container_name.data(), container_name.length(), SQLITE_STATIC) == SQLITE_OK && + sqlite3_step(stmt) == SQLITE_DONE) + { + sqlite3_finalize(stmt); + return 0; + } + LOG_ERROR << "Error deleting container " << container_name; + return -1; + } } diff --git a/src/sqlite.hpp b/src/sqlite.hpp index fd6c793..ee99adf 100644 --- a/src/sqlite.hpp +++ b/src/sqlite.hpp @@ -82,5 +82,7 @@ namespace sqlite int get_instance(sqlite3 *db, std::string_view container_name, hp::instance_info &instance); int get_allocated_instance_count(sqlite3 *db); + + int delete_hp_instance(sqlite3 *db, std::string_view container_name); } #endif