39 #include <sys/types.h>
54 #define HONEY_FORMAT_VERSION DATE_TO_VERSION(2018,4,3)
80 #define DATE_TO_VERSION(Y,M,D) \
81 ((unsigned(Y) - 2014) << 9 | unsigned(M) << 5 | unsigned(D))
82 #define VERSION_TO_YEAR(V) ((unsigned(V) >> 9) + 2014)
83 #define VERSION_TO_MONTH(V) ((unsigned(V) >> 5) & 0x0f)
84 #define VERSION_TO_DAY(V) (unsigned(V) & 0x1f)
86 #define HONEY_VERSION_MAGIC_LEN 14
87 #define HONEY_VERSION_MAGIC_AND_VERSION_LEN 16
90 '\x0f',
'\x0d',
'X',
'a',
'p',
'i',
'a',
'n',
' ',
'H',
'o',
'n',
'e',
'y',
99 string msg =
"lseek failed on file descriptor ";
121 string msg =
"Failed to rewind file descriptor ";
128 filename +=
"/iamhoney";
130 if (
rare(fd_in < 0)) {
131 string msg = filename;
132 msg +=
": Failed to open honey revision file for reading";
133 if (errno == ENOENT || errno == ENOTDIR) {
144 const char* end =
p +
io_read(fd_in, buf,
sizeof(buf), 33);
159 msg +=
"Database is format version ";
163 msg +=
" but I only understand ";
179 for (
unsigned table_no = 0; table_no <
Honey::MAX_; ++table_no) {
180 if (!
root[table_no].unserialise(&
p, end)) {
249 "Bad serialised DB stats (overflowed)" :
250 "Bad serialised DB stats (out of data)";
270 if (
p == end || *
p ==
'\0') {
283 "Bad serialised unique_terms bounds (overflowed)" :
284 "Bad serialised unique_terms bounds (out of data)";
348 for (
unsigned table_no = 0; table_no <
Honey::MAX_; ++table_no) {
357 LOGCALL(DB,
const string,
"HoneyVersion::write", new_rev|flags);
364 for (
unsigned table_no = 0; table_no <
Honey::MAX_; ++table_no) {
377 tmpfile +=
"/iamhoney";
381 int open_flags = O_CREAT|O_TRUNC|O_WRONLY|
O_BINARY;
384 string msg =
"Couldn't write new rev file: ";
418 int fd_to_close =
fd;
424 int save_errno = errno;
425 (void)
close(fd_to_close);
426 if (!tmpfile.empty())
427 (
void)unlink(tmpfile.c_str());
432 if (
close(fd_to_close) != 0) {
433 if (!tmpfile.empty()) {
434 int save_errno = errno;
435 (void)unlink(tmpfile.c_str());
441 if (!tmpfile.empty()) {
448 for (
unsigned table_no = 0; table_no <
Honey::MAX_; ++table_no) {
478 for (
unsigned table_no = 0; table_no <
Honey::MAX_; ++table_no) {
499 std::make_unsigned_t<off_t> uoffset =
offset;
513 std::make_unsigned_t<off_t> uoffset, uroot;
515 unsigned dummy_blocksize;
524 root = uoffset + uroot;
528 (void)dummy_blocksize;
The HoneyVersion class manages the revision files.
void create()
Create the version file.
Xapian::termcount get_spelling_wordfreq_upper_bound() const
Xapian::doccount doccount
The number of documents in the database.
Xapian::termcount doclen_lbound
A lower bound on the smallest document length in this database.
honey_revision_number_t oldest_changeset
Oldest changeset removed when max_changesets is set.
Xapian::termcount doclen_ubound
An upper bound on the greatest document length in this database.
void merge_stats(const HoneyVersion &o)
Merge the database stats.
off_t offset
Offset into the file at which the version data starts.
bool sync(const std::string &tmpfile, honey_revision_number_t new_rev, int flags)
Xapian::termcount get_doclength_lower_bound() const
const std::string write(honey_revision_number_t new_rev, int flags)
Xapian::totallength get_total_doclen() const
Xapian::termcount get_unique_terms_upper_bound() const
honey_revision_number_t rev
std::string db_dir
The database directory.
Xapian::docid last_docid
Greatest document id ever used in this database.
Xapian::totallength total_doclen
The total of the lengths of all documents in the database.
Honey::RootInfo old_root[Honey::MAX_]
HoneyVersion(std::string_view db_dir_)
Xapian::termcount spelling_wordfreq_ubound
An upper bound on the spelling wordfreq in this database.
Xapian::termcount get_unique_terms_lower_bound() const
void read()
Read the version file and check it's a version we understand.
Xapian::termcount get_wdf_upper_bound() const
std::string serialised_stats
The serialised database stats.
Honey::RootInfo root[Honey::MAX_]
Xapian::doccount get_doccount() const
Xapian::termcount uniq_terms_ubound
An upper bound on the number of unique terms in a document in this database.
Xapian::termcount uniq_terms_lbound
A lower bound on the number of unique terms in a document in this database.
Xapian::termcount get_doclength_upper_bound() const
Xapian::termcount wdf_ubound
An upper bound on the greatest wdf in this database.
Uuid uuid
The UUID of this database.
void init(uint4 compress_min_)
bool unserialise(const char **p, const char *end)
uint4 compress_min
Should be >= 4 or 0 for no compression.
std::string fl_serialised
void serialise(std::string &s) const
honey_tablesize_t num_entries
static constexpr unsigned BINARY_SIZE
The size of a UUID in bytes.
void assign(const char *p)
const char * data() const
DatabaseCorruptError indicates database corruption was detected.
DatabaseError indicates some sort of database related error.
Indicates an attempt to access a database not present.
DatabaseOpeningError indicates failure to open a database.
DatabaseVersionError indicates that a database is in an unsupported format.
Constants in the Xapian namespace.
#define LOGCALL(CATEGORY, TYPE, FUNC, PARAMS)
#define LOGCALL_VOID(CATEGORY, FUNC, PARAMS)
Hierarchy of classes which Xapian can throw as exceptions.
Wrapper class around a file descriptor to avoid leaks.
Definitions, types, etc for use inside honey.
uint4 honey_revision_number_t
The revision number of a honey database.
const size_t COMPRESS_MIN
#define VERSION_TO_MONTH(V)
#define HONEY_VERSION_MAGIC_LEN
static const char HONEY_VERSION_MAGIC[HONEY_VERSION_MAGIC_AND_VERSION_LEN]
#define HONEY_FORMAT_VERSION
Honey format version (date of change):
#define VERSION_TO_DAY(V)
#define VERSION_TO_YEAR(V)
#define HONEY_VERSION_MAGIC_AND_VERSION_LEN
static const uint4 compress_min_tab[]
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
size_t io_read(int fd, char *p, size_t n, size_t min)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
bool io_tmp_rename(const std::string &tmp_file, const std::string &real_file)
Rename a temporary file to its final position.
Wrappers for low-level POSIX I/O routines.
bool io_sync(int fd)
Ensure all data previously written to file descriptor fd has been written to disk.
bool io_full_sync(int fd)
Return the smaller of two numbers which isn't zero.
constexpr std::enable_if_t< std::is_unsigned_v< T >, T > min_non_zero(const T &a, const T &b)
Return the smaller of two unsigned integers which isn't zero.
string str(int value)
Convert int to std::string.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DB_NO_SYNC
Don't attempt to ensure changes have hit disk.
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
const int DB_FULL_SYNC
Try to ensure changes are really written to disk.
XAPIAN_TOTALLENGTH_TYPE totallength
The total length of all documents in a database.
const int DB_DANGEROUS
Update the database in-place.
Various assertion macros.
#define AssertRel(A, REL, B)
Pack types into strings and unpack them again.
bool unpack_string(const char **p, const char *end, std::string &result)
Decode a std::string from a string.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
void pack_string(std::string &s, std::string_view value)
Append an encoded std::string to a string.
Provides wrappers with POSIXy semantics.
include <fcntl.h>, but working around broken platforms.
include <sys/stat.h> with portability enhancements
<unistd.h>, but with compat.
Convert types to std::string.
Various handy string-related helpers.
Class for handling UUIDs.