summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/nsr-recon/src/recon_xlator.h
blob: c0f1e2145de226c08f9b399b5e30d5cac32adb77 (plain)
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
/*
  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#ifndef __RECON_XLATOR_H__
#define __RECON_XLATOR_H__

#include <semaphore.h>
#include <pthread.h>

enum gf_dht_mem_types_ {
        gf_mt_recon_private_t = gf_common_mt_end + 1,
};

enum nsr_recon_xlator_sector_t {
        nsr_recon_xlator_sector_0 = 0, // to report back the status of given transaction ids
        nsr_recon_xlator_sector_1 = 512, //  to write here information about leadership changes from the brick
        nsr_recon_xlator_sector_2 = (512 * 2), // to write here individual roles and wait for that role to be done
        nsr_recon_xlator_sector_3 = (512 *3), // read from here to get term info for given term
        nsr_recon_xlator_sector_4 = (512 * 4), // read from here to get last term info
};


typedef struct _nsr_recon_private_s {
        xlator_t *this; //back pointer
        unsigned int replica_group_size; // number of static members of replica group
        char **replica_group_members; // replica group members (including itself in first slot)
        pthread_t thread_id; // driver thread id
        nsr_recon_driver_ctx_t *driver_thread_context; //driver thread context
        unsigned int outstanding; // for communicating with driver thread
        call_frame_t *frame; // old frame that is pending (just one as of now)
        struct list_head list;
        char *volname;
        uint32_t txn_id;
        char *changelog_base_path;
        char *base_dir;
#ifdef  NSR_DEBUG
        uint32_t recon_main_log_fd;
#endif
} nsr_recon_private_t;

#define atomic_cmpxchg         __sync_val_compare_and_swap

/*
 * REVIEW
 * Ideally, use gf_log like everyone else.  Failing that, at least put the logs
 * with all the others in /var/log instead of /tmp.
 */
#ifdef NSR_DEBUG
#define recon_main_log(dom, levl, fmt...) \
        { \
                nsr_recon_private_t   *priv   = this->private;  \
                char c[255]; \
                if (!priv->recon_main_log_fd) { \
                        mkdir("/tmp/nsr-logs/", 0777);  \
                        priv->recon_main_log_fd = open("/tmp/nsr-logs/recon-main-log", O_RDWR|O_CREAT|O_TRUNC); \
                } \
                sprintf(c, fmt); \
                write(priv->recon_main_log_fd, c, strlen(c));  \
        }
#else
#define recon_main_log(dom, levl, fmt...) gf_log(dom, levl, fmt)
#endif


void nsr_recon_libchangelog_get_this_term_info(xlator_t *this, char *bp, int32_t term, nsr_recon_last_term_info_t *lt);
void nsr_recon_libchangelog_get_last_term_info(xlator_t *this, char *bp, int32_t term, nsr_recon_last_term_info_t *lt);
void nsr_recon_return_back(nsr_recon_private_t *priv, uint32_t term_id);
void nsr_recon_libchangelog_get_records(xlator_t *this, char *bp, int32_t term, uint32_t first, uint32_t last, void *buf);


#endif /* #ifndef __RECON_XLATOR_H__ */