~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/rep/rep_region.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 2001-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
#include "db_config.h"
8
 
 
9
 
#ifndef lint
10
 
static const char revid[] = "$Id$";
11
 
#endif /* not lint */
12
 
 
13
 
#ifndef NO_SYSTEM_INCLUDES
14
 
#endif
15
 
 
16
 
#include <string.h>
17
 
 
18
 
#include "db_int.h"
19
 
#include "dbinc/rep.h"
20
 
#include "dbinc/log.h"
21
 
 
22
 
/*
23
 
 * __rep_region_init --
24
 
 *      Initialize the shared memory state for the replication system.
25
 
 *
26
 
 * PUBLIC: int __rep_region_init __P((DB_ENV *));
27
 
 */
28
 
int
29
 
__rep_region_init(dbenv)
30
 
        DB_ENV *dbenv;
31
 
{
32
 
        REGENV *renv;
33
 
        REGINFO *infop;
34
 
        DB_MUTEX *db_mutexp;
35
 
        DB_REP *db_rep;
36
 
        REP *rep;
37
 
        int ret;
38
 
 
39
 
        db_rep = dbenv->rep_handle;
40
 
        infop = dbenv->reginfo;
41
 
        renv = infop->primary;
42
 
        ret = 0;
43
 
 
44
 
        MUTEX_LOCK(dbenv, &renv->mutex);
45
 
        if (renv->rep_off == INVALID_ROFF) {
46
 
                /* Must create the region. */
47
 
                if ((ret = __db_shalloc(infop->addr,
48
 
                    sizeof(REP), MUTEX_ALIGN, &rep)) != 0)
49
 
                        goto err;
50
 
                memset(rep, 0, sizeof(*rep));
51
 
                rep->tally_off = INVALID_ROFF;
52
 
                renv->rep_off = R_OFFSET(infop, rep);
53
 
 
54
 
                if ((ret = __db_mutex_setup(dbenv, infop, &rep->mutex,
55
 
                    MUTEX_NO_RECORD)) != 0)
56
 
                        goto err;
57
 
 
58
 
                /*
59
 
                 * We must create a place for the db_mutex separately;
60
 
                 * mutexes have to be aligned to MUTEX_ALIGN, and the only way
61
 
                 * to guarantee that is to make sure they're at the beginning
62
 
                 * of a shalloc'ed chunk.
63
 
                 */
64
 
                if ((ret = __db_shalloc(infop->addr, sizeof(DB_MUTEX),
65
 
                    MUTEX_ALIGN, &db_mutexp)) != 0)
66
 
                        goto err;
67
 
                rep->db_mutex_off = R_OFFSET(infop, db_mutexp);
68
 
 
69
 
                /*
70
 
                 * Because we have no way to prevent deadlocks and cannot log
71
 
                 * changes made to it, we single-thread access to the client
72
 
                 * bookkeeping database.  This is suboptimal, but it only gets
73
 
                 * accessed when messages arrive out-of-order, so it should
74
 
                 * stay small and not be used in a high-performance app.
75
 
                 */
76
 
                if ((ret = __db_mutex_setup(dbenv, infop, db_mutexp,
77
 
                    MUTEX_NO_RECORD)) != 0)
78
 
                        goto err;
79
 
 
80
 
                /* We have the region; fill in the values. */
81
 
                rep->eid = DB_EID_INVALID;
82
 
                rep->master_id = DB_EID_INVALID;
83
 
                rep->gen = 0;
84
 
 
85
 
                /*
86
 
                 * Set default values for the min and max log records that we
87
 
                 * wait before requesting a missing log record.
88
 
                 */
89
 
                rep->request_gap = DB_REP_REQUEST_GAP;
90
 
                rep->max_gap = DB_REP_MAX_GAP;
91
 
        } else
92
 
                rep = R_ADDR(infop, renv->rep_off);
93
 
        MUTEX_UNLOCK(dbenv, &renv->mutex);
94
 
 
95
 
        db_rep->mutexp = &rep->mutex;
96
 
        db_rep->db_mutexp = R_ADDR(infop, rep->db_mutex_off);
97
 
        db_rep->region = rep;
98
 
 
99
 
        return (0);
100
 
 
101
 
err:    MUTEX_UNLOCK(dbenv, &renv->mutex);
102
 
        return (ret);
103
 
}
104
 
 
105
 
/*
106
 
 * __rep_region_destroy --
107
 
 *      Destroy any system resources allocated in the replication region.
108
 
 *
109
 
 * PUBLIC: int __rep_region_destroy __P((DB_ENV *));
110
 
 */
111
 
int
112
 
__rep_region_destroy(dbenv)
113
 
        DB_ENV *dbenv;
114
 
{
115
 
        DB_REP *db_rep;
116
 
        int ret, t_ret;
117
 
 
118
 
        ret = t_ret = 0;
119
 
        db_rep = (DB_REP *)dbenv->rep_handle;
120
 
 
121
 
        if (db_rep != NULL) {
122
 
                if (db_rep->mutexp != NULL)
123
 
                        ret = __db_mutex_destroy(db_rep->mutexp);
124
 
                if (db_rep->db_mutexp != NULL)
125
 
                        t_ret = __db_mutex_destroy(db_rep->db_mutexp);
126
 
        }
127
 
 
128
 
        return (ret == 0 ? t_ret : ret);
129
 
}
130
 
 
131
 
/*
132
 
 * __rep_dbenv_close --
133
 
 *      Replication-specific destruction of the DB_ENV structure.
134
 
 *
135
 
 * PUBLIC: int __rep_dbenv_close __P((DB_ENV *));
136
 
 */
137
 
int
138
 
__rep_dbenv_close(dbenv)
139
 
        DB_ENV *dbenv;
140
 
{
141
 
        DB_REP *db_rep;
142
 
 
143
 
        db_rep = (DB_REP *)dbenv->rep_handle;
144
 
 
145
 
        if (db_rep != NULL) {
146
 
                __os_free(dbenv, db_rep);
147
 
                dbenv->rep_handle = NULL;
148
 
        }
149
 
 
150
 
        return (0);
151
 
}
152
 
 
153
 
/*
154
 
 * __rep_preclose --
155
 
 *      If we are a client, shut down our client database and, if we're
156
 
 * actually closing the environment, close all databases we've opened
157
 
 * while applying messages.
158
 
 *
159
 
 * PUBLIC: int __rep_preclose __P((DB_ENV *, int));
160
 
 */
161
 
int
162
 
__rep_preclose(dbenv, do_closefiles)
163
 
        DB_ENV *dbenv;
164
 
        int do_closefiles;
165
 
{
166
 
        DB *dbp;
167
 
        DB_REP *db_rep;
168
 
        int ret, t_ret;
169
 
 
170
 
        ret = t_ret = 0;
171
 
 
172
 
        /* If replication is not initialized, we have nothing to do. */
173
 
        if ((db_rep = (DB_REP *)dbenv->rep_handle) == NULL)
174
 
                return (0);
175
 
 
176
 
        if ((dbp = db_rep->rep_db) != NULL) {
177
 
                MUTEX_LOCK(dbenv, db_rep->db_mutexp);
178
 
                ret = dbp->close(dbp, 0);
179
 
                db_rep->rep_db = NULL;
180
 
                MUTEX_UNLOCK(dbenv, db_rep->db_mutexp);
181
 
        }
182
 
 
183
 
        if (do_closefiles)
184
 
                t_ret = __dbreg_close_files(dbenv);
185
 
 
186
 
        return (ret == 0 ? t_ret : ret);
187
 
}