diff --git a/src/idempotency/server/server_handler.c b/src/idempotency/server/server_handler.c index a62dcf8..0214697 100644 --- a/src/idempotency/server/server_handler.c +++ b/src/idempotency/server/server_handler.c @@ -189,7 +189,7 @@ IdempotencyRequest *sf_server_update_prepare_and_check( } adheader = (SFProtoIdempotencyAdditionalHeader *)req->body; - request = (IdempotencyRequest *)fast_mblock_alloc_object(request_allocator); + request = fast_mblock_alloc_object(request_allocator); if (request == NULL) { *result = ENOMEM; return NULL; diff --git a/src/sf_binlog_writer.c b/src/sf_binlog_writer.c index 7c21c21..d3dd1fb 100644 --- a/src/sf_binlog_writer.c +++ b/src/sf_binlog_writer.c @@ -217,11 +217,13 @@ static int deal_binlog_records(SFBinlogWriterThread *thread, return ERRNO_THREAD_EXIT; case SF_BINLOG_BUFFER_TYPE_SET_NEXT_VERSION: if (current->writer->order_by != - SF_BINLOG_WRITER_TYPE_ORDER_BY_VERSION) + SF_BINLOG_WRITER_TYPE_ORDER_BY_VERSION && + current->writer->thread->order_mode != + SF_BINLOG_THREAD_ORDER_MODE_VARY) { logWarning("file: "__FILE__", line: %d, " - "subdir_name: %s, invalid order by: %d != %d, " - "maybe some mistake happen", __LINE__, + "subdir_name: %s, order by: %d != %d, " + "maybe some mistake happen?", __LINE__, current->writer->fw.cfg.subdir_name, current->writer->order_by, SF_BINLOG_WRITER_TYPE_ORDER_BY_VERSION); @@ -239,8 +241,10 @@ static int deal_binlog_records(SFBinlogWriterThread *thread, __LINE__, current->writer->fw.cfg.subdir_name, current->version.first); - if (current->writer->version_ctx.next != - current->version.first) + if ((current->writer->order_by == + SF_BINLOG_WRITER_TYPE_ORDER_BY_NONE) || + (current->writer->version_ctx.next != + current->version.first)) { binlog_writer_set_next_version(current->writer, current->version.first); diff --git a/src/sf_configs.h b/src/sf_configs.h index 1ccf476..e7a4504 100644 --- a/src/sf_configs.h +++ b/src/sf_configs.h @@ -142,23 +142,23 @@ static inline const char *sf_get_replication_quorum_caption( } } -static inline bool sf_replication_quorum_check(const SFReplicationQuorum quorum, - const int total_count, const int active_slave_count) +#define SF_REPLICATION_QUORUM_MAJORITY(server_count, success_count) \ + ((success_count == server_count) || (success_count > server_count / 2)) + +static inline bool sf_replication_quorum_check(const SFReplicationQuorum + quorum, const int server_count, const int success_count) { switch (quorum) { case sf_replication_quorum_any: return true; case sf_replication_quorum_auto: - if (total_count % 2 == 0) { + if (server_count % 2 == 0) { return true; //same as sf_replication_quorum_any } //continue case sf_replication_quorum_majority: - if ((active_slave_count + 1) == total_count) { - return true; - } else { - return (active_slave_count + 1) > total_count / 2; - } + return SF_REPLICATION_QUORUM_MAJORITY( + server_count, success_count); } }