Make MKSNAP return code 3 for `howmany != 0`

To streamline the actions we'll make sure that mksnap returns code 3
if an incorrect number of arguments are provided
The actiondoc for the `mksnap` action was added and the contributing
guide was also updated

Signed-off-by: Sayan Nandan <nandansayan@outlook.com>
next
Sayan Nandan 4 years ago
parent a3c5135022
commit 11a9223e6b
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

@ -32,15 +32,23 @@ In other cases, use the C style.
### Parts of the project
The project root has three main directories:
* `ci` , `.github` : CI scripts (which, under normal circumstances, don't need to be modified)
* `cli` : Source for `tsh` which is the command-line client for TDB
* `examples` : Example configuration files
* `libtdb` : This contains functions, structs, ... used by both the `cli` and the
* `server` : Source for the main database server `tdb`
* `tdb-bench` : The source for the benchmarking tool resides here
* `tdb-macros` : The source for custom compiler macros used by TerrabaseDB
* `cli` : This contains code for `tsh` which is the command-line client for TDB
* `libtdb` : This contains function, structs, ... used by both the `cli` and the `server`
* `server` : This contains code for the main database server
### Jargon
Each project has its own jargon — and so do we!
* _actiondoc_ and _actions docs_ : This refers to the `actions.jsonc` file, which is used by the TerrabaseDB documentation website for automatically building documentation for the actions
### Branches
The `next` branch is the _kind of_ stable branch which contains the latest changes. However, for most purposes, you should always download the sources from the tags. Usually, when a feature is worked on, the work will be done on a separate branch, and then it will be merged into next.
The `next` branch is the _kind of_ stable branch which contains the latest changes. However, for most purposes, you should always download sources from the tags. Usually, when a feature is worked on, the work will be done on a separate branch, and then it will be merged into next.
## Steps

@ -143,5 +143,13 @@
"args": "KEYLEN <key>",
"desc": "Returns the length of the UTF-8 string",
"return": "Length of the key as an unsigned int",
},
{
"name": "MKSNAP",
"since": "0.4.5",
"complexity": "O(n)",
"args": "MKSNAP",
"desc": "Create a snapshot",
"return": "Okay if succeeded, otherwise it returns `err-snapshot-disabled` if snapshotting is disabled or `err-snapshot-busy` if a snapshotting operation is already in progress"
}
]
]

@ -23,6 +23,7 @@
use crate::config::SnapshotConfig;
use crate::coredb::CoreDB;
#[cfg(test)]
use crate::coredb::SnapshotStatus;
use crate::diskstore;
use chrono::prelude::*;

@ -30,16 +30,15 @@ use std::hint::unreachable_unchecked;
/// Create a snapshot
///
pub async fn mksnap(handle: &CoreDB, con: &mut Connection, act: ActionGroup) -> TResult<()> {
if !handle.is_snapshot_enabled() {
// Since snapshotting is disabled, we can't create a snapshot!
// We'll just return an error returning the same
let error = "Snapshotting is disabled";
con.write_response(GroupBegin(1)).await?;
let error = RespCodes::OtherError(Some(error.to_string()));
return con.write_response(error).await;
}
let howmany = act.howmany();
if howmany == 0 {
if act.howmany() == 0 {
if !handle.is_snapshot_enabled() {
// Since snapshotting is disabled, we can't create a snapshot!
// We'll just return an error returning the same
let error = "err-snapshot-disabled";
con.write_response(GroupBegin(1)).await?;
let error = RespCodes::OtherError(Some(error.to_string()));
return con.write_response(error).await;
}
// We will just follow the standard convention of creating snapshots
let mut was_engine_error = false;
let mut outerror = None;
@ -70,7 +69,7 @@ pub async fn mksnap(handle: &CoreDB, con: &mut Connection, act: ActionGroup) ->
}
if engine_was_busy {
con.write_response(GroupBegin(1)).await?;
let error = RespCodes::OtherError(Some("Snapshotting already in progress".to_owned()));
let error = RespCodes::OtherError(Some("err-snapshot-busy".to_owned()));
return con.write_response(error).await;
}
if let Some(val) = outerror {
@ -90,7 +89,7 @@ pub async fn mksnap(handle: &CoreDB, con: &mut Connection, act: ActionGroup) ->
// We shouldn't ever reach here if all our logic is correct
// but if we do, something is wrong with the runtime
con.write_response(GroupBegin(1)).await?;
let error = RespCodes::OtherError(Some("access-after-termsig".to_owned()));
let error = RespCodes::OtherError(Some("err-access-after-termsig".to_owned()));
return con.write_response(error).await;
}
} else {

Loading…
Cancel
Save