}
#endif
-int BlueFS::_flush(FileWriter *h, bool force)
+int BlueFS::_flush(FileWriter *h, bool force, std::unique_lock<ceph::mutex>& l)
+{
+ bool flushed = false;
+ int r = _flush(h, force, &flushed);
+ if (r == 0 && flushed) {
+ _maybe_compact_log(l);
+ }
+ return r;
+}
+
+int BlueFS::_flush(FileWriter *h, bool force, bool *flushed)
{
h->buffer_appender.flush();
uint64_t length = h->buffer.length();
uint64_t offset = h->pos;
+ if (flushed) {
+ *flushed = false;
+ }
if (!force &&
length < cct->_conf->bluefs_min_flush_size) {
dout(10) << __func__ << " " << h << " ignoring, length " << length
<< std::hex << offset << "~" << length << std::dec
<< " to " << h->file->fnode << dendl;
ceph_assert(h->pos <= h->file->fnode.size);
- return _flush_range(h, offset, length);
+ int r = _flush_range(h, offset, length);
+ if (flushed) {
+ *flushed = true;
+ }
+ return r;
}
int BlueFS::_truncate(FileWriter *h, uint64_t offset)
PExtentVector* extents);
int _flush_range(FileWriter *h, uint64_t offset, uint64_t length);
- int _flush(FileWriter *h, bool force);
+ int _flush(FileWriter *h, bool focce, std::unique_lock<ceph::mutex>& l);
+ int _flush(FileWriter *h, bool force, bool *flushed = nullptr);
int _fsync(FileWriter *h, std::unique_lock<ceph::mutex>& l);
#ifdef HAVE_LIBAIO
uint64_t jump_to = 0);
uint64_t _estimate_log_size();
bool _should_compact_log();
- void _maybe_compact_log(std::unique_lock<ceph::mutex>& l);
enum {
REMOVE_DB = 1,
/// sync any uncommitted state to disk
void sync_metadata(bool avoid_compact);
+ /// test and compact log, if necessary
+ void _maybe_compact_log(std::unique_lock<ceph::mutex>& l);
void set_slow_device_expander(BlueFSDeviceExpander* a) {
slow_dev_expander = a;
void handle_discard(unsigned dev, interval_set<uint64_t>& to_release);
void flush(FileWriter *h, bool force = false) {
- std::lock_guard l(lock);
- _flush(h, force);
+ std::unique_lock l(lock);
+ int r = _flush(h, force, l);
+ ceph_assert(r == 0);
}
void flush_range(FileWriter *h, uint64_t offset, uint64_t length) {
std::lock_guard l(lock);
}
int fsync(FileWriter *h) {
std::unique_lock l(lock);
- return _fsync(h, l);
+ int r = _fsync(h, l);
+ _maybe_compact_log(l);
+ return r;
}
int read(FileReader *h, FileReaderBuffer *buf, uint64_t offset, size_t len,
bufferlist *outbl, char *out) {