raft_unstable_log.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/*
 * Copyright (c) 2019 TAOS Data, Inc. <cli@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TD_SYNC_RAFT_UNSTABLE_LOG_H
#define TD_SYNC_RAFT_UNSTABLE_LOG_H

#include "sync_type.h"

/* in-memory unstable raft log storage */
struct SSyncRaftUnstableLog {
#if 0
  /* Circular buffer of log entries */
  RaftEntry *entries;

  /* size of Circular buffer */
  int size;

  /* Indexes of used slots [front, back) */
  int front, back;

  /* Index of first entry is offset + 1 */
  SyncIndex offset;

  /* meta data of snapshot */
  SSyncRaftUnstableLog snapshot;
#endif
};

/**
 * return index of last in memory log, return 0 if log is empty
 **/
SyncIndex syncRaftLogLastIndex(SSyncRaftUnstableLog* pLog);

#if 0
void raftLogInit(RaftLog* pLog);

void raftLogClose(RaftLog* pLog);

/**
 * When startup populating log entrues loaded from disk,
 * init raft memory log with snapshot index,term and log start idnex.
 **/ 
/*
void raftLogStart(RaftLog* pLog,
                  RaftSnapshotMeta snapshot,
                  SyncIndex startIndex);
*/
/** 
 * Get the number of entries the log. 
 **/
int raftLogNumEntries(const RaftLog* pLog);



/**
 * return last term of in memory log, return 0 if log is empty
 **/
SSyncTerm raftLogLastTerm(RaftLog* pLog);

/**
 * return term of log with the given index, return 0 if the term of index cannot be found
 * , errCode will save the error code.
 **/
SSyncTerm raftLogTermOf(RaftLog* pLog, SyncIndex index, RaftCode* errCode);

/** 
 * Get the last index of the most recent snapshot. Return 0 if there are no *
 * snapshots. 
 **/
SyncIndex raftLogSnapshotIndex(RaftLog* pLog);

/* Append a new entry to the log. */
int raftLogAppend(RaftLog* pLog,
                  SSyncTerm term,
                  const SSyncBuffer *buf);

/**
 * acquire log from given index onwards.
 **/ 
/*
int raftLogAcquire(RaftLog* pLog,
                  SyncIndex index,
                  RaftEntry **ppEntries,
                  int *n);

void raftLogRelease(RaftLog* pLog,
                    SyncIndex index,
                    RaftEntry *pEntries,
                    int n);
*/
/* Delete all entries from the given index (included) onwards. */
void raftLogTruncate(RaftLog* pLog, SyncIndex index);

/** 
 * when taking a new snapshot, the function will update the last snapshot information and delete
 * all entries up last_index - trailing (included). If the log contains no entry
 * a last_index - trailing, then no entry will be deleted. 
 **/
void raftLogSnapshot(RaftLog* pLog, SyncIndex index, SyncIndex trailing);

#endif

#endif /* TD_SYNC_RAFT_UNSTABLE_LOG_H */