[pybsddb] Replication stat question

Sury Soni ssoni at nextdigital.com
Thu Oct 2 09:13:55 CEST 2008


Here is the solution.

 

Seems like, python implementation around C/C++ function rep_stat() is
altogether missing.

 

Hence, I simply copied code from repmgr_stat() wrapper and modified the
statistic receiving object type and fetched statistics of my interest in
the dictionary.

 

I would have loved to implement full thing and provided the patch, but I
am bit lazy to learn how to get patch and submit more professionally.

 

But following is a quick code reference for those who are stuck (or will
stuck) in similar situation.

 

In file, Modules/_bsddb.c, 

 

1. find implementation code for 

 

static PyObject*

DBEnv_repmgr_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs)

 

2. Copy paste full function implementation just next to it.

 

3. Change 

 

DB_REPMGR_STAT *statp 

to 

DB_REP_STAT *statp 

 

4. Pick fields of DB_REP_STAT of your interest or someone implement it
fully. 

Ref.
http://www.oracle.com/technology/documentation/berkeley-db/db/api_c/rep_
stat.html

 

 

5. Sample code as follows:

 

static PyObject*

DBEnv_rep_stat(DBEnvObject* self, PyObject* args, PyObject *kwargs)

{

    int err;

    int flags=0;

    DB_REP_STAT *statp;

    PyObject *stats;

    static char* kwnames[] = { "flags", NULL };

 

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:rep_stat",

                kwnames, &flags))

    {

        return NULL;

    }

    CHECK_ENV_NOT_CLOSED(self);

    MYDB_BEGIN_ALLOW_THREADS;

    err = self->db_env->rep_stat(self->db_env, &statp, flags);

    MYDB_END_ALLOW_THREADS;

    RETURN_IF_ERR();

 

    stats=PyDict_New();

    if (stats == NULL) {

        free(statp);

        return NULL;

    }

 

#define MAKE_ENTRY(name)  _addIntToDict(stats, #name, statp->st_##name)

#define MAKE_DB_LSN_ENTRY(name) _addDB_lsnToDict(stats, #name,
statp->st_##name)

    MAKE_DB_LSN_ENTRY(next_lsn);

#undef MAKE_DB_LSN_ENTRY

#undef MAKE_ENTRY

 

    free(statp);

    return stats;

}

 

6. Add entry into following array

static PyMethodDef DBEnv_methods[] = {

...

...

#if (DBVER >= 46)

    {"repmgr_stat", (PyCFunction)DBEnv_repmgr_stat,

        METH_VARARGS|METH_KEYWORDS},

    {"rep_stat", (PyCFunction)DBEnv_rep_stat,

        METH_VARARGS|METH_KEYWORDS},

    {"repmgr_stat_print", (PyCFunction)DBEnv_repmgr_stat_print,

        METH_VARARGS|METH_KEYWORDS},

#endif

...

...

 

 

7. That's it, build, test and install.

 

8. And yes, I have tried to small test case in existing test case, which
is not appropriate:

 

# Code to add few records into master.

# Write yourself, I picked the place where in some test, it was adding
some items.

 

        statm = self.dbenvMaster.rep_stat()

        m_lsn = statm['next_lsn']

        statc = self.dbenvClient.rep_stat()

        c_lsn = statc['next_lsn']

        self.assertEquals(m_lsn, c_lsn)

 

 

I hope it is useful. Even though, my presentation is not alright, but
thanks to this community who made my life lot easier by implementing
this wrapper API.

 

Regards,

 

Surya

 

________________________________

From: pybsddb-bounces at argo.es [mailto:pybsddb-bounces at argo.es] On Behalf
Of Sury Soni
Sent: Wednesday, 1 October 2008 11:50 AM
To: pybsddb at argo.es
Subject: [pybsddb] Replication stat question

 

Hi There,

 

I am using pybsddb3 (3.4.7.2) wrapped around db4.6.21 on freebsd 7.

 

I am curious to get st_next_lsn DB_LSN attribute from replication stats.

 

How can I get?

 

My curiosity is to get last LSN number on replication client which can
be later matched with master to verify how close up-to-date client is
with the master.

 

Repmgr_stat does not fill this attribute and rep_stat is virtual
function but have this attribute. How can I get this attribute for
default replication manager.

 

Regards,

____________________________________
Sury Prakash Soni
Developer
____________________________________

Next Digital
Level 8, 15 William St, Melbourne 
VIC 3000 Australia
p +61 3 8612 6888
f  +61 3 8612 6899
m 0433 661 327
ssoni at nextdigital.com <mailto:ssoni at nextdigital.com> 
www.nextdigital.com <http://www.nextdigital.com/> 
____________________________________

This email and any attachments are intended only for the use of the
recipient and may be confidential and/or legally privileged. Next
Digital Group Pty Ltd ("Next Digital") disclaims liability for any
errors, omissions, viruses, loss and/or damage arising from using,
opening or transmitting this email. If you are not the intended
recipient you must not use, interfere with, disclose, copy or retain
this email and you should notify the sender immediately by return email
or by contacting Next Digital by telephone on +61 3 8612 6888.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.jcea.es/pipermail/pybsddb/attachments/20081002/96c4850e/attachment.htm>


More information about the pybsddb mailing list