Merge pull request #24039 from taosdata/FIX/TD-27843-3.0
enh: resend new snap replication msg on all acked if not finished yet
This commit is contained in:
commit
3be9af9765
|
@ -115,7 +115,7 @@ static int32_t tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return
|
||||||
static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) {
|
static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
ASSERT(writer->ctx->offset == writer->file.size);
|
ASSERT(writer->ctx->offset <= writer->file.size);
|
||||||
ASSERT(writer->config->fid == writer->file.fid);
|
ASSERT(writer->config->fid == writer->file.fid);
|
||||||
|
|
||||||
STFileOp op = (STFileOp){
|
STFileOp op = (STFileOp){
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
|
||||||
static void syncSnapBufferReset(SSyncSnapBuffer *pBuf) {
|
static void syncSnapBufferReset(SSyncSnapBuffer *pBuf) {
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
|
||||||
for (int64_t i = pBuf->start; i < pBuf->end; ++i) {
|
for (int64_t i = pBuf->start; i < pBuf->end; ++i) {
|
||||||
if (pBuf->entryDeleteCb) {
|
if (pBuf->entryDeleteCb) {
|
||||||
pBuf->entryDeleteCb(pBuf->entries[i % pBuf->size]);
|
pBuf->entryDeleteCb(pBuf->entries[i % pBuf->size]);
|
||||||
|
@ -34,7 +33,6 @@ static void syncSnapBufferReset(SSyncSnapBuffer *pBuf) {
|
||||||
pBuf->start = SYNC_SNAPSHOT_SEQ_BEGIN + 1;
|
pBuf->start = SYNC_SNAPSHOT_SEQ_BEGIN + 1;
|
||||||
pBuf->end = pBuf->start;
|
pBuf->end = pBuf->start;
|
||||||
pBuf->cursor = pBuf->start - 1;
|
pBuf->cursor = pBuf->start - 1;
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncSnapBufferDestroy(SSyncSnapBuffer **ppBuf) {
|
static void syncSnapBufferDestroy(SSyncSnapBuffer **ppBuf) {
|
||||||
|
@ -198,20 +196,23 @@ void snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
// update flag
|
// update flag
|
||||||
int8_t stopped = !atomic_val_compare_exchange_8(&pSender->start, true, false);
|
int8_t stopped = !atomic_val_compare_exchange_8(&pSender->start, true, false);
|
||||||
if (stopped) return;
|
if (stopped) return;
|
||||||
|
taosThreadMutexLock(&pSender->pSndBuf->mutex);
|
||||||
|
{
|
||||||
|
pSender->finish = finish;
|
||||||
|
pSender->waitTime = -1;
|
||||||
|
|
||||||
pSender->finish = finish;
|
// close reader
|
||||||
pSender->waitTime = -1;
|
if (pSender->pReader != NULL) {
|
||||||
|
pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
||||||
|
pSender->pReader = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// close reader
|
syncSnapBufferReset(pSender->pSndBuf);
|
||||||
if (pSender->pReader != NULL) {
|
|
||||||
pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
SRaftId destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pSender->pReader = NULL;
|
sSInfo(pSender, "snapshot sender stop, to dnode:%d, finish:%d", DID(&destId), finish);
|
||||||
}
|
}
|
||||||
|
taosThreadMutexUnlock(&pSender->pSndBuf->mutex);
|
||||||
syncSnapBufferReset(pSender->pSndBuf);
|
|
||||||
|
|
||||||
SRaftId destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
|
||||||
sSInfo(pSender, "snapshot sender stop, to dnode:%d, finish:%d", DID(&destId), finish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncSnapSendMsg(SSyncSnapshotSender *pSender, int32_t seq, void *pBlock, int32_t blockLen, int32_t typ) {
|
int32_t syncSnapSendMsg(SSyncSnapshotSender *pSender, int32_t seq, void *pBlock, int32_t blockLen, int32_t typ) {
|
||||||
|
@ -324,6 +325,9 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
SSyncSnapBuffer *pSndBuf = pSender->pSndBuf;
|
SSyncSnapBuffer *pSndBuf = pSender->pSndBuf;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
taosThreadMutexLock(&pSndBuf->mutex);
|
taosThreadMutexLock(&pSndBuf->mutex);
|
||||||
|
if (pSender->pReader == NULL || pSender->finish || !snapshotSenderIsStart(pSender)) {
|
||||||
|
goto _out;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t seq = pSndBuf->cursor + 1; seq < pSndBuf->end; ++seq) {
|
for (int32_t seq = pSndBuf->cursor + 1; seq < pSndBuf->end; ++seq) {
|
||||||
SyncSnapBlock *pBlk = pSndBuf->entries[seq % pSndBuf->size];
|
SyncSnapBlock *pBlk = pSndBuf->entries[seq % pSndBuf->size];
|
||||||
|
@ -338,6 +342,12 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
pBlk->sendTimeMs = nowMs;
|
pBlk->sendTimeMs = nowMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSender->seq != SYNC_SNAPSHOT_SEQ_END && pSndBuf->end <= pSndBuf->start) {
|
||||||
|
if (snapshotSend(pSender) != 0) {
|
||||||
|
goto _out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END && pSndBuf->end <= pSndBuf->start) {
|
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END && pSndBuf->end <= pSndBuf->start) {
|
||||||
if (syncSnapSendMsg(pSender, pSender->seq, NULL, 0, 0) != 0) {
|
if (syncSnapSendMsg(pSender, pSender->seq, NULL, 0, 0) != 0) {
|
||||||
goto _out;
|
goto _out;
|
||||||
|
@ -514,19 +524,22 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
|
|
||||||
int8_t stopped = !atomic_val_compare_exchange_8(&pReceiver->start, true, false);
|
int8_t stopped = !atomic_val_compare_exchange_8(&pReceiver->start, true, false);
|
||||||
if (stopped) return;
|
if (stopped) return;
|
||||||
|
taosThreadMutexLock(&pReceiver->pRcvBuf->mutex);
|
||||||
if (pReceiver->pWriter != NULL) {
|
{
|
||||||
int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, false,
|
if (pReceiver->pWriter != NULL) {
|
||||||
&pReceiver->snapshot);
|
int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter,
|
||||||
if (ret != 0) {
|
false, &pReceiver->snapshot);
|
||||||
sRError(pReceiver, "snapshot receiver stop write failed since %s", terrstr());
|
if (ret != 0) {
|
||||||
|
sRError(pReceiver, "snapshot receiver stop write failed since %s", terrstr());
|
||||||
|
}
|
||||||
|
pReceiver->pWriter = NULL;
|
||||||
|
} else {
|
||||||
|
sRInfo(pReceiver, "snapshot receiver stop, writer is null");
|
||||||
}
|
}
|
||||||
pReceiver->pWriter = NULL;
|
|
||||||
} else {
|
|
||||||
sRInfo(pReceiver, "snapshot receiver stop, writer is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
syncSnapBufferReset(pReceiver->pRcvBuf);
|
syncSnapBufferReset(pReceiver->pRcvBuf);
|
||||||
|
}
|
||||||
|
taosThreadMutexUnlock(&pReceiver->pRcvBuf->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||||
|
|
Loading…
Reference in New Issue