Skip to content

Commit b3168c5

Browse files
author
鲁鹏帆
committed
follow empiredan advice
1 parent ecb0152 commit b3168c5

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

src/replica/duplication/load_from_private_log.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ void load_from_private_log::find_log_file_to_start()
158158
// is cleared once WAL replay finished. They are unable to read.
159159
mutation_log::log_file_map_by_index new_file_map;
160160

161-
decree cleanable_decree = _private_log->get_cleanable_decree();
162-
decree max_decree_gpid = _private_log->max_decree(get_gpid());
161+
const auto decree cleanable_decree = _private_log->get_cleanable_decree();
162+
const auto decree max_decree_gpid = _private_log->max_decree(get_gpid());
163163

164164
if (max_decree_gpid <= cleanable_decree) {
165-
LOG_ERROR_PREFIX("plog_file all error: max_decree_gpid {} , cleanable_decree {}",
165+
LOG_ERROR_PREFIX("max_decree_gpid({}) should be > cleanable_decree({}) for plog",
166166
max_decree_gpid,
167167
cleanable_decree);
168168
return;
@@ -178,12 +178,9 @@ void load_from_private_log::find_log_file_to_start()
178178

179179
new_file_map.emplace(it->first, file);
180180

181-
// next file map may can not open
182-
gpid pid = get_gpid();
183-
decree previous_log_max_decree = file->previous_log_max_decree(pid);
184-
// these plog_file has possible be deleted do not open_read next plog_file , otherwise it
185-
// may coredump
186-
if (previous_log_max_decree <= cleanable_decree) {
181+
// If the max decree of a log file falls within `cleanable_decree`, the file may be deleted
182+
// during the GC of plog files. Therefore, these files should be skipped here.
183+
if (cleanable_decree >= file->previous_log_max_decree(get_gpid())) {
187184
break;
188185
}
189186
}

src/replica/mutation_log.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "task/task_code.h"
4848
#include "task/task_tracker.h"
4949
#include "utils/autoref_ptr.h"
50+
#include "utils/ports.h"
5051
#include "utils/error_code.h"
5152
#include "utils/errors.h"
5253
#include "utils/zlocks.h"
@@ -404,7 +405,10 @@ class mutation_log : public ref_counter
404405
// be less than _plog_max_decree_on_disk.
405406
decree _plog_max_commit_on_disk;
406407

407-
decree _cleanable_decree; // for gc crush
408+
// The decree threshold for private log garbage collection. Mutations with decree <= this
409+
// value are considered cleanable and their log files may be deleted by GC.
410+
// Protected by _lock in get/set.
411+
decree _cleanable_decree;
408412
};
409413

410414
using mutation_log_ptr = dsn::ref_ptr<mutation_log>;
@@ -425,18 +429,12 @@ class mutation_log_private : public mutation_log, private replica_base
425429
_tracker.cancel_outstanding_tasks();
426430
}
427431

428-
// Non-copyable and non-movable
429-
mutation_log_private(const mutation_log_private &) = delete;
430-
mutation_log_private &operator=(const mutation_log_private &) = delete;
431-
mutation_log_private(mutation_log_private &&) = delete;
432-
mutation_log_private &operator=(mutation_log_private &&) = delete;
433-
434432
::dsn::task_ptr append(mutation_ptr &mu,
435433
dsn::task_code callback_code,
436434
dsn::task_tracker *tracker,
437435
aio_handler &&callback,
438-
int hash,
439-
int64_t *pending_size) override;
436+
int hash = 0,
437+
int64_t *pending_size = nullptr) override;
440438

441439
bool get_learn_state_in_memory(decree start_decree, binary_writer &writer) const override;
442440

@@ -449,6 +447,9 @@ class mutation_log_private : public mutation_log, private replica_base
449447
void flush_once() override;
450448

451449
private:
450+
DISALLOW_COPY_AND_ASSIGN(mutation_log_private);
451+
DISALLOW_MOVE_AND_ASSIGN(mutation_log_private);
452+
452453
// async write pending mutations into log file
453454
// Preconditions:
454455
// - _pending_write != nullptr

0 commit comments

Comments
 (0)