pybsddb with cffi

Check-in [98750dee3e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Trying to pass test_distributed_transactions - no success
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:98750dee3e19d77ef73cf6ce90e50ff824834bcb
User & Date: broker-3 2013-02-07 14:39:29
Context
2013-02-07
15:12
Corrected exception check-in: 39064e3640 user: broker-3 tags: trunk
14:39
Trying to pass test_distributed_transactions - no success check-in: 98750dee3e user: broker-3 tags: trunk
13:56
passed test_compare check-in: bb079ca309 user: broker-3 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bsddb3/db.py.

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
....
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410






1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424


1425
1426


1427
1428
1429
1430
1431
1432
1433
1434
....
1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450
1451
1452
1453
....
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482

1483




1484
1485
1486
1487
1488
1489
1490
1491
....
1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517
1518



1519
1520
1521
1522
1523
1524
1525
        # no check_error here
        self.db_env.get_home(self.db_env, home)
        if home[0]:
            return ffi.string(home[0])

    def txn_begin(self, parent=None, flags=0):
        assert parent is None or isinstance(parent, DBTxn)
        return DBTxn(self, parent, flags)

    def txn_checkpoint(self, kbyte=0, min=0, flags=0):
        check_error(self.db_env.txn_checkpoint(self.db_env, kbyte, min, flags))

    def log_file(self, file_and_offset):
        lsn = ffi.new("DB_LSN *")
        lsn.file, lsn.offset = file_and_offset
................................................................................
        check_error(self.db_env.log_flush(self.db_env, ffi.NULL))

    def txn_recover(self):
        flags = DB_FIRST
        PREPLIST_LEN = 16
        retp = ffi.new("long *")
        preplist = ffi.new("DB_PREPLIST []", PREPLIST_LEN)
        ret = []
        while True:
            check_error(self.db_env.txn_recover(self.db_env, preplist, PREPLIST_LEN, retp, flags))
            retp = retp[0]
            if not retp:
                break
            raise Exception("Not yet")






        return ret

    def __del__(self):  # DBEnv_dealloc
        if self.db_env is not None:
            self.close()


class DBTxn(object):
    def __init__(self, db_env, parent_txn, flags):
        parent_txn = parent_txn.txn if parent_txn else ffi.NULL

        txn = ffi.new("DB_TXN **")
        env = db_env.db_env
        self.txn = None


        check_error(env.txn_begin(env, parent_txn, txn, flags))
        self.txn = txn[0]


        # self.flag_prepare = 0  no `prepare` method implemented yet
        # self.children_txns = []
        self.children_dbs = set()
        self.children_cursors = set()
        self.children_sequences = set()
        self.db_env = db_env
        if parent_txn:
            raise Exception("Not yet(DBTxn with parent txn)")
................................................................................
        if self.txn is None:
            raise DBCursorClosedError(0, "DBTxn must not be used after" \
                                      "txn_commit, txn_abort or txn_discard")

    def commit(self, flags=0):
        self._close_cursors()
        self._check_txn()

        self.db_env.children_txns.discard(ref(self))
        try:
            try:
                check_error(self.txn.commit(self.txn, flags))
            finally:
                # _promote_transaction_dbs_and_sequences
                for db in self.children_dbs:
................................................................................
            warn("Must close cursors before resolving a transaction.",
                 RuntimeWarning)
            cursor.close()
        assert not self.children_cursors

    def _abort_discard(self, discard):  # DBTxn_abort_discard_internal
        self._check_txn()
        self.db_env.children_txns.discard(ref(self))
        self._close_cursors()
        for sequence in _iter_wset(self.children_sequences):
            sequence.close()
        for db in _iter_wset(self.children_dbs):
            db.close()

        try:




            check_error(self.txn.abort(self.txn))
        finally:
            self.txn = None

    def abort(self):
        self._abort_discard(False)

    def discard(self):
................................................................................
    def prepare(self, gid):
        assert isinstance(gid, str)
        if len(gid) != DB_GID_SIZE:
            raise TypeError("gid must be DB_GID_SIZE bytes long")
        if self.txn is None:
            raise DBError(0, "DBTxn must not be used after txn_commit, "
                          "txn_abort or txn_discard")

        check_error(self.txn.prepare(self.txn, gid))

    def __del__(self):
        if self.txn is not None:
            try:
                self.abort()



            finally:
                self.db_env = None
                # self.parent_txn = None


class DBLogCursor(object):
    def __init__(self, logc, env):







|







 







|


|
|

|
>
>
>
>
>
>
|







|

<
<

<
>
>
|
|
>
>
|







 







>







 







<





>

>
>
>
>
|







 







>






>
>
>







977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
....
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426


1427

1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
....
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
....
1478
1479
1480
1481
1482
1483
1484

1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
....
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
        # no check_error here
        self.db_env.get_home(self.db_env, home)
        if home[0]:
            return ffi.string(home[0])

    def txn_begin(self, parent=None, flags=0):
        assert parent is None or isinstance(parent, DBTxn)
        return DBTxn(self, parent, None, flags)

    def txn_checkpoint(self, kbyte=0, min=0, flags=0):
        check_error(self.db_env.txn_checkpoint(self.db_env, kbyte, min, flags))

    def log_file(self, file_and_offset):
        lsn = ffi.new("DB_LSN *")
        lsn.file, lsn.offset = file_and_offset
................................................................................
        check_error(self.db_env.log_flush(self.db_env, ffi.NULL))

    def txn_recover(self):
        flags = DB_FIRST
        PREPLIST_LEN = 16
        retp = ffi.new("long *")
        preplist = ffi.new("DB_PREPLIST []", PREPLIST_LEN)
        ret_list = []
        while True:
            check_error(self.db_env.txn_recover(self.db_env, preplist, PREPLIST_LEN, retp, flags))
            ret = retp[0]
            if not ret:
                break
            flags = DB_NEXT
            for i in xrange(ret):
                prep = preplist[i]
                gid = ffi.buffer(prep.gid, DB_GID_SIZE)
                txn = DBTxn(self, None, prep.txn, 0)
                txn.flag_prepare = 1  # Recover state
                ret_list.append((gid, txn))
        return ret_list

    def __del__(self):  # DBEnv_dealloc
        if self.db_env is not None:
            self.close()


class DBTxn(object):
    def __init__(self, db_env, parent_txn, txn, flags):
        parent_txn = parent_txn.txn if parent_txn else ffi.NULL


        env = db_env.db_env

        if txn is None:
            txn = ffi.new("DB_TXN **")
            check_error(env.txn_begin(env, parent_txn, txn, flags))
            self.txn = txn[0]
        else:
            self.txn = None
        self.flag_prepare = 0
        # self.children_txns = []
        self.children_dbs = set()
        self.children_cursors = set()
        self.children_sequences = set()
        self.db_env = db_env
        if parent_txn:
            raise Exception("Not yet(DBTxn with parent txn)")
................................................................................
        if self.txn is None:
            raise DBCursorClosedError(0, "DBTxn must not be used after" \
                                      "txn_commit, txn_abort or txn_discard")

    def commit(self, flags=0):
        self._close_cursors()
        self._check_txn()
        self.flag_prepare = 0
        self.db_env.children_txns.discard(ref(self))
        try:
            try:
                check_error(self.txn.commit(self.txn, flags))
            finally:
                # _promote_transaction_dbs_and_sequences
                for db in self.children_dbs:
................................................................................
            warn("Must close cursors before resolving a transaction.",
                 RuntimeWarning)
            cursor.close()
        assert not self.children_cursors

    def _abort_discard(self, discard):  # DBTxn_abort_discard_internal
        self._check_txn()

        self._close_cursors()
        for sequence in _iter_wset(self.children_sequences):
            sequence.close()
        for db in _iter_wset(self.children_dbs):
            db.close()
        self.db_env.children_txns.discard(ref(self))
        try:
            if discard:
                assert not self.flag_prepare
                check_error(self.txn.discard(self.txn, 0))
            elif not self.flag_prepare:
                check_error(self.txn.abort(self.txn))
        finally:
            self.txn = None

    def abort(self):
        self._abort_discard(False)

    def discard(self):
................................................................................
    def prepare(self, gid):
        assert isinstance(gid, str)
        if len(gid) != DB_GID_SIZE:
            raise TypeError("gid must be DB_GID_SIZE bytes long")
        if self.txn is None:
            raise DBError(0, "DBTxn must not be used after txn_commit, "
                          "txn_abort or txn_discard")
        self.flag_prepare = 1
        check_error(self.txn.prepare(self.txn, gid))

    def __del__(self):
        if self.txn is not None:
            try:
                self.abort()
                if not self.flag_prepare:
                    raise RuntimeWarning("DBTxn aborted in destructor. "
                                         "No prior commit() or abort().")
            finally:
                self.db_env = None
                # self.parent_txn = None


class DBLogCursor(object):
    def __init__(self, logc, env):