38 #include <boost/algorithm/string.hpp>
47 #include <sys/types.h>
57 const int32_t FS_BUFFER_SIZE = -1;
58 const int64_t FS_BLOCK_SIZE = -1;
65 std::vector<EntityPtr> &initial_entities)
66 : m_fs(fs), m_definition(definition) {
72 boost::trim_right_if(
m_path, boost::is_any_of(
"/"));
128 lock_guard<mutex> lock(
m_mutex);
150 m_fs->remove(tmp_name);
191 uint32_t total_length {};
193 total_length += entry.second.first;
197 StaticBuffer buf (
new uint8_t [total_length], total_length);
198 uint8_t *ptr = buf.
base;
199 for (
auto &entry : m_entity_map) {
200 memcpy(ptr, entry.second.second.get(), entry.second.first);
201 ptr += entry.second.first;
228 uint8_t *ptr = buf.
base;
230 for (
auto & sb : m_write_queue) {
231 memcpy(ptr, sb->base, sb->size);
241 m_write_queue.clear();
257 unique_lock<mutex> lock(
m_mutex);
264 lock_guard<mutex> lock(
m_mutex);
267 auto duration = chrono::system_clock::now().time_since_epoch();
268 auto millis = chrono::duration_cast<chrono::milliseconds>(duration).count();
269 uint32_t duration_millis = m_interval - (millis % m_interval);
271 if ((error = m_comm->set_timer(duration_millis, shared_from_this())) !=
Error::OK)
279 lock_guard<mutex> lock(
m_mutex);
282 m_writer->signal_write_ready();
295 memset(header.
name, 0,
sizeof(header.
name));
298 uint8_t *ptr = buf.
base;
316 unique_lock<mutex> lock(
m_mutex);
324 lock_guard<Entity> lock(*entity);
326 buf = make_shared<StaticBuffer>(length);
327 uint8_t *ptr = buf->base;
329 if (entity->marked_for_removal())
330 entity->header.encode( &ptr );
332 entity->encode_entry( &ptr );
334 HT_ASSERT((ptr-buf->base) == (ptrdiff_t)buf->size);
337 shared_ptr<uint8_t> backup_buf(
new uint8_t [length], default_delete<uint8_t[]>());
338 memcpy(backup_buf.get(), buf->base, buf->size);
341 if (dynamic_cast<EntityRecover *>(entity.get()) ==
nullptr) {
343 if (!entity->marked_for_removal())
357 unique_lock<mutex> lock(
m_mutex);
358 shared_ptr<StaticBuffer> buffers(
new StaticBuffer[entities.size()], default_delete<StaticBuffer[]>() );
361 size_t total_length = 0;
363 if (entities.empty())
370 for (
auto & entity : entities) {
371 lock_guard<Entity> lock(*entity);
373 buffers.get()[i].set(
new uint8_t [length], length);
374 ptr = buffers.get()[i].base;
375 if (entity->marked_for_removal())
376 entity->header.encode( &ptr );
378 entity->encode_entry( &ptr );
381 HT_ASSERT(dynamic_cast<EntityRecover *>(entity.get()) ==
nullptr);
383 if (!entity->marked_for_removal()) {
384 shared_ptr<uint8_t> backup_buf(
new uint8_t [length], default_delete<uint8_t[]>());
385 memcpy(backup_buf.get(), buffers.get()[i].base, length);
389 HT_ASSERT((ptr-buffers.get()[i].base) == (ptrdiff_t)buffers.get()[i].size);
390 total_length += length;
396 for (i=0; i<entities.size(); i++) {
397 memcpy(ptr, buffers.get()[i].base, buffers.get()[i].size);
398 ptr += buffers.get()[i].size;
400 HT_ASSERT((ptr-buf->base) == (ptrdiff_t)buf->size);
413 unique_lock<mutex> lock(
m_mutex);
415 uint8_t *ptr = buf->base;
421 entity->header.length = 0;
422 entity->header.checksum = 0;
424 entity->header.encode( &ptr );
426 HT_ASSERT((ptr-buf->base) == (ptrdiff_t)buf->size);
442 unique_lock<mutex> lock(
m_mutex);
444 if (entities.empty())
452 uint8_t *ptr = buf->base;
454 for (
auto &entity : entities) {
456 entity->header.length = 0;
457 entity->header.checksum = 0;
458 entity->header.encode( &ptr );
463 HT_ASSERT((ptr-buf->base) == (ptrdiff_t)buf->size);
477 lock_guard<mutex> lock(
m_mutex);
static Comm * instance()
Creates/returns singleton instance of the Comm class.
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
A memory buffer of static size.
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
Compatibility class for boost::filesystem::path.
std::shared_ptr< Entity > EntityPtr
Smart pointer to Entity.
static bool unlink(const String &fname)
Unlinks (deletes) a file or directory.
Filesystem::Flags convert(std::string str)
Converts string mnemonic to corresponding Filesystem::Flags value.
static ssize_t write(const String &fname, const std::string &contents)
Writes a String buffer to a file; the file is overwritten if it already exists.
static bool exists(const String &fname)
Checks if a file or directory exists.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
static bool mkdirs(const String &dirname)
Creates a directory (with all parent directories, if required)
#define HT_EXPECT(_e_, _code_)
Compatibility class for boost::filesystem::path.
File system utility functions.
Static length of entity header.
const char * get_text(int error)
Returns a descriptive error message.
Compatibility Macros for C/C++.
#define HT_FATALF(msg,...)
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
#define HT_THROWF(_code_, _fmt_,...)
This is a generic exception class for Hypertable.
String extensions and helpers: sets, maps, append operators etc.
std::shared_ptr< StaticBuffer > StaticBufferPtr
Smart pointer to StaticBuffer.
std::shared_ptr< Definition > DefinitionPtr
Smart pointer to Definition.
int code() const
Returns the error code.