mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 09:55:45 +02:00
* chore: factor out rdb_load utilities into separate files rdb_load.cc is huge and contains many auxillary classes. This PR moves DecompressImpl and ErrorRdb code into detail/ It also fixes minor bugs around error conditions with de-compression: a. Do not check-fail on invalid opcode and return error_code instead. b. Print correctly LZ4 errors. Signed-off-by: Roman Gershman <roman@dragonflydb.io> * chore: fixes --------- Signed-off-by: Roman Gershman <roman@dragonflydb.io>
84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
// Copyright 2022, DragonflyDB authors. All rights reserved.
|
|
// See LICENSE for licensing terms.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <system_error>
|
|
|
|
#include "facade/error.h"
|
|
|
|
namespace dfly {
|
|
|
|
using facade::kDbIndOutOfRangeErr;
|
|
using facade::kInvalidDbIndErr;
|
|
using facade::kInvalidIntErr;
|
|
using facade::kSyntaxErr;
|
|
using facade::kWrongTypeErr;
|
|
|
|
#ifndef RETURN_ON_ERR
|
|
|
|
#define RETURN_ON_ERR_T(T, x) \
|
|
do { \
|
|
std::error_code __ec = (x); \
|
|
if (__ec) { \
|
|
DLOG(ERROR) << "Error while calling " #x ": " << __ec.message(); \
|
|
return (T)(__ec); \
|
|
} \
|
|
} while (0)
|
|
|
|
#define RETURN_ON_ERR(x) RETURN_ON_ERR_T(std::error_code, x)
|
|
|
|
#endif // RETURN_ON_ERR
|
|
|
|
#ifndef RETURN_ON_BAD_STATUS
|
|
|
|
#define RETURN_ON_BAD_STATUS(x) \
|
|
do { \
|
|
OpStatus __s = (x).status(); \
|
|
if (__s != OpStatus::OK) { \
|
|
return __s; \
|
|
} \
|
|
} while (0)
|
|
|
|
#endif // RETURN_ON_BAD_STATUS
|
|
|
|
#ifndef GET_OR_SEND_UNEXPECTED
|
|
|
|
#define GET_OR_SEND_UNEXPECTED(expr) \
|
|
({ \
|
|
auto expr_res = (expr); \
|
|
if (!expr_res) { \
|
|
builder->SendError(expr_res.error()); \
|
|
return; \
|
|
} \
|
|
std::move(expr_res).value(); \
|
|
})
|
|
|
|
#endif // GET_OR_SEND_UNEXPECTED
|
|
|
|
namespace rdb {
|
|
|
|
enum errc {
|
|
wrong_signature = 1,
|
|
bad_version = 2,
|
|
feature_not_supported = 3,
|
|
duplicate_key = 4,
|
|
rdb_file_corrupted = 5,
|
|
bad_checksum = 6,
|
|
bad_db_index = 7,
|
|
invalid_rdb_type = 8,
|
|
invalid_encoding = 9,
|
|
empty_key = 10,
|
|
out_of_memory = 11,
|
|
bad_json_string = 12,
|
|
unsupported_operation = 13,
|
|
};
|
|
|
|
} // namespace rdb
|
|
|
|
std::error_code RdbError(rdb::errc ev);
|
|
|
|
} // namespace dfly
|