46 if (changes_fd >= 0) {
48 string changes_tmp = changes_stem;
65 const char *
p = getenv(
"XAPIAN_MAX_CHANGESETS");
69 "a non-negative integer");
75 if (max_changesets == 0)
78 string changes_tmp = changes_stem;
81 O_WRONLY | O_CREAT | O_TRUNC |
O_CLOEXEC, 0666);
83 string message =
"Couldn't open changeset ";
84 message += changes_tmp;
85 message +=
" to write";
101 io_write(changes_fd, header.data(), header.size());
122 string changes_tmp = changes_stem;
123 changes_tmp +=
"tmp";
126 int saved_errno = errno;
127 (void)::
close(changes_fd);
129 (void)unlink(changes_tmp.c_str());
130 string m = changes_tmp;
131 m +=
": Failed to sync";
135 (void)::
close(changes_fd);
138 string changes_file = changes_stem;
139 changes_file +=
str(new_rev - 1);
142 string m = changes_tmp;
143 m +=
": Failed to rename to ";
148 if (new_rev <= max_changesets) {
159 while (oldest_changeset < stop_changeset) {
160 changes_file.resize(changes_stem.size());
161 changes_file +=
str(oldest_changeset);
172 string message =
"Couldn't open changeset ";
173 message += changes_file;
189 const char * end = buf + n;
198 if (
p == end || (*
p != 0 && *
p != 1))
205 n +=
io_read(fd, buf + n,
sizeof(buf) - n);
213 unsigned char v = *
p++;
224 if (
rev != version_rev)
229 if (len <=
size_t(end -
p)) {
232 if (lseek(fd, len - (end -
p), SEEK_CUR) < 0)
239 unsigned table = (v & 0x7);
257 unsigned level =
static_cast<unsigned char>(
p[4]);
261 if (block_size <=
unsigned(end -
p)) {
264 if (lseek(fd, block_size - (end -
p), SEEK_CUR) < 0)
void write_block(const char *p, size_t len)
GlassChanges * start(glass_revision_number_t old_rev, glass_revision_number_t rev, int flags)
static void check(const std::string &changes_file)
void commit(glass_revision_number_t new_rev, int flags)
DatabaseError indicates some sort of database related error.
InvalidArgumentError indicates an invalid parameter value was passed to the API.
Constants in the Xapian namespace.
Hierarchy of classes which Xapian can throw as exceptions.
Wrapper class around a file descriptor to avoid leaks.
Definitions, types, etc for use inside glass.
#define GLASS_MIN_BLOCKSIZE
Minimum B-tree block size.
uint4 glass_revision_number_t
The revision number of a glass database.
Internal definitions for glass database replication.
#define CHANGES_MAGIC_STRING
bool io_unlink(const std::string &filename)
Delete a file.
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.
string str(int value)
Convert int to std::string.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
const int DB_NO_SYNC
Don't attempt to ensure changes have hit disk.
const int DB_DANGEROUS
Update the database in-place.
Pack types into strings and unpack them again.
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.
Parse signed and unsigned type from string and check for trailing characters.
bool parse_unsigned(const char *p, T &res)
Provides wrappers with POSIXy semantics.
Convert types to std::string.
Various handy string-related helpers.
#define CONST_STRLEN(S)
Returns the length of a string constant.
functions for reading and writing different width words
uint32_t unaligned_read4(const unsigned char *ptr)