BDB事务共享区域

Jun 07, 2016 pm 04:26 PM
사무 공유됨 구역 영역 우리를 마침내

最后我们来看一下事务共享区域。 首先仍然是每个进程都有的一个数据结构__db_txnmgr{}: /** The transaction manager encapsulates the transaction system. It contains* references to the log and lock managers as well as the state that keeps* track

最后我们来看一下事务共享区域。

首先仍然是每个进程都有的一个数据结构__db_txnmgr{}:

<code>/*
* The transaction manager encapsulates the transaction system.  It contains
* references to the log and lock managers as well as the state that keeps
* track of the shared memory region.
*/
struct __db_txnmgr {
/* These fields need to be protected for multi-threaded support. */
    db_mutex_t    *mutexp;    /* Synchronization. */
                    /* list of active transactions */
    TAILQ_HEAD(_chain, __db_txn)    txn_chain;
/* These fields are not protected. */
    REGINFO        reginfo;    /* Region information. */
    DB_ENV        *dbenv;        /* Environment. */
    int (*recover)            /* Recovery dispatch routine */
        __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
    u_int32_t     flags;        /* DB_TXN_NOSYNC, DB_THREAD */
    DB_TXNREGION    *region;    /* address of shared memory region */
    void        *mem;        /* address of the shalloc space */
};
</code>
로그인 후 복사

同样拥有一个指向描述共享区域的reginfo字段和指向共享区域的指针mem。

<code>/*
* Layout of the shared memory region.
* The region consists of a DB_TXNREGION structure followed by a large
* pool of shalloc'd memory which is used to hold TXN_DETAIL structures
* and thread mutexes (which are dynamically allocated).
*/
struct __db_txnregion {
    RLAYOUT        hdr;        /* Shared memory region header. */
    u_int32_t    magic;        /* transaction magic number */
    u_int32_t    version;    /* version number */
    u_int32_t    maxtxns;    /* maximum number of active txns */
    u_int32_t    last_txnid;    /* last transaction id given out */
    DB_LSN        pending_ckp;    /* last checkpoint did not finish */
    DB_LSN        last_ckp;    /* lsn of the last checkpoint */
    time_t        time_ckp;    /* time of last checkpoint */
    u_int32_t    logtype;    /* type of logging */
    u_int32_t    locktype;    /* lock type */
    u_int32_t    naborts;    /* number of aborted transactions */
    u_int32_t    ncommits;    /* number of committed transactions */
    u_int32_t    nbegins;    /* number of begun transactions */
    SH_TAILQ_HEAD(_active) active_txn;    /* active transaction list */
};
</code>
로그인 후 복사

共享区域除了有个公用的头部hdr字段以外,最重要的是有一个所有活动事务的列表active_txn字段。

现在让我们看一下这些数据结构和共享区域的创建或打开以及初始化操作。

在db_appinit()函数中调用txn_open()函数打开或连接一个事务共享区域:

<code>if (LF_ISSET(DB_INIT_TXN) && (ret = txn_open(NULL,
    LF_ISSET(DB_CREATE | DB_THREAD | DB_TXN_NOSYNC),
    mode, dbenv, &dbenv->tx_info)) != 0)
    goto err;
</code>
로그인 후 복사

其中txn_open定义如下:

<code>int
txn_open(path, flags, mode, dbenv, mgrpp)
    const char *path;
    u_int32_t flags;
    int mode;
    DB_ENV *dbenv;
    DB_TXNMGR **mgrpp;
{
    DB_TXNMGR *tmgrp;
    u_int32_t maxtxns;
    int ret;
    /* Validate arguments. */
    首先仍然是验证参数
    然后用malloc创建每个进程都有的事务管理器结构
    /* Now, create the transaction manager structure and set its fields. */
    if ((ret = __os_calloc(1, sizeof(DB_TXNMGR), &tmgrp)) != 0)
        return (ret);
    并初始化事务管理器结构
    /* Initialize the transaction manager structure. */
    tmgrp->mutexp = NULL;
    tmgrp->dbenv = dbenv;
    tmgrp->recover =
        dbenv->tx_recover == NULL ? __db_dispatch : dbenv->tx_recover;
    tmgrp->flags = LF_ISSET(DB_TXN_NOSYNC | DB_THREAD);
    TAILQ_INIT(&tmgrp->txn_chain);
    现在开始创建或连接到一个事务共享区域
    /* Join/create the txn region. */
    首先还是一样,填充区域描述信息REGINFO{},然后调用__db_rattach()函数创建或打开一个共享区域
    tmgrp->reginfo.dbenv = dbenv;
    tmgrp->reginfo.appname = DB_APP_NONE;
    if (path == NULL)
        tmgrp->reginfo.path = NULL;
    else
        if ((ret = __os_strdup(path, &tmgrp->reginfo.path)) != 0)
            goto err;
    tmgrp->reginfo.file = DEFAULT_TXN_FILE;
    tmgrp->reginfo.mode = mode;
    tmgrp->reginfo.size = TXN_REGION_SIZE(maxtxns);
    tmgrp->reginfo.dbflags = flags;
    tmgrp->reginfo.addr = NULL;
    tmgrp->reginfo.fd = -1;
    tmgrp->reginfo.flags = dbenv->tx_max == 0 ? REGION_SIZEDEF : 0;
    if ((ret = __db_rattach(&tmgrp->reginfo)) != 0)
        goto err;
    /* Fill in region-related fields. */
    tmgrp->region = tmgrp->reginfo.addr;
    tmgrp->mem = &tmgrp->region[1];
    if (F_ISSET(&tmgrp->reginfo, REGION_CREATED)) {
        tmgrp->region->maxtxns = maxtxns;
        if ((ret = __txn_init(tmgrp->region)) != 0)
            goto err;
    } else if (tmgrp->region->magic != DB_TXNMAGIC) {
        /* Check if valid region. */
        __db_err(dbenv, "txn_open: Bad magic number");
        ret = EINVAL;
        goto err;
    }
    // 如果这是一个新的事务共享区域,初始化之。这里又和MPOOL一样,
    // 使用__shmalloc函数管理共享区域内存
    if (LF_ISSET(DB_THREAD)) {
        if ((ret = __db_shalloc(tmgrp->mem, sizeof(db_mutex_t),
            MUTEX_ALIGNMENT, &tmgrp->mutexp)) == 0)
            /*
            * Since we only get here if threading is turned on, we
            * know that we have spinlocks, so the offset is going
            * to be ignored.  We put 0 here as a valid placeholder.
            */
            __db_mutex_init(tmgrp->mutexp, 0);
        if (ret != 0)
            goto err;
    }
    UNLOCK_TXNREGION(tmgrp);
    *mgrpp = tmgrp;
    return (0);
err:    if (tmgrp->reginfo.addr != NULL) {
        if (tmgrp->mutexp != NULL)
            __db_shalloc_free(tmgrp->mem, tmgrp->mutexp);
        UNLOCK_TXNREGION(tmgrp);
        (void)__db_rdetach(&tmgrp->reginfo);
        if (F_ISSET(&tmgrp->reginfo, REGION_CREATED))
            (void)txn_unlink(path, 1, dbenv);
    }
    if (tmgrp->reginfo.path != NULL)
        __os_freestr(tmgrp->reginfo.path);
    __os_free(tmgrp, sizeof(*tmgrp));
    return (ret);
}
</code>
로그인 후 복사

这个函数就是txn_open()调用来初始化事务共享区域的函数:

<code>/*
* This file contains the top level routines of the transaction library.
* It assumes that a lock manager and log manager that conform to the db_log(3)
* and db_lock(3) interfaces exist.
*
* Initialize a transaction region in shared memory.
* Return 0 on success, errno on failure.
*/
static int
__txn_init(txn_region)
    DB_TXNREGION *txn_region;
{
    time_t now;
    (void)time(&now);
    /* maxtxns is already initialized. */
    txn_region->magic = DB_TXNMAGIC;
    txn_region->version = DB_TXNVERSION;
    txn_region->last_txnid = TXN_MINIMUM;
    /*
    * XXX
    * If we ever do more types of locking and logging, this changes.
    */
    txn_region->logtype = 0;
    txn_region->locktype = 0;
    txn_region->time_ckp = now;
    ZERO_LSN(txn_region->last_ckp);
    ZERO_LSN(txn_region->pending_ckp);
    SH_TAILQ_INIT(&txn_region->active_txn);
    __db_shalloc_init((void *)&txn_region[1],
        TXN_REGION_SIZE(txn_region->maxtxns) - sizeof(DB_TXNREGION));
    return (0);
}
</code>
로그인 후 복사

其中DB_TXN{}是每个事务的描述符(定义在db_int.h文件中):

<code>/* The structure allocated for every transaction. */
struct __db_txn {
    DB_TXNMGR    *mgrp;        /* Pointer to transaction manager. */
    DB_TXN        *parent;    /* Pointer to transaction's parent. */
    DB_LSN        last_lsn;    /* Lsn of last log write. */
    u_int32_t    txnid;        /* Unique transaction id. */
    size_t        off;        /* Detail structure within region. */
    TAILQ_ENTRY(__db_txn) links;    /* Links transactions off manager. */
    TAILQ_HEAD(__kids, __db_txn) kids; /* Child transactions. */
    TAILQ_ENTRY(__db_txn) klinks;    /* Links child transactions. */
#define    TXN_MALLOC    0x01        /* Structure allocated by TXN system. */
    u_int32_t    flags;
};
typedef struct __txn_detail {
    u_int32_t txnid;        /* current transaction id
                    used to link free list also */
    DB_LSN    last_lsn;        /* last lsn written for this txn */
    DB_LSN    begin_lsn;        /* lsn of begin record */
    size_t    last_lock;        /* offset in lock region of last lock
                    for this transaction. */
    size_t    parent;            /* Offset of transaction's parent. */
#define    TXN_UNALLOC    0
#define    TXN_RUNNING    1
#define    TXN_ABORTED    2
#define    TXN_PREPARED    3
#define    TXN_COMMITTED    4
    u_int32_t status;        /* status of the transaction */
    SH_TAILQ_ENTRY    links;        /* free/active list */
#define    TXN_XA_ABORTED        1
#define    TXN_XA_DEADLOCKED    2
#define    TXN_XA_ENDED        3
#define    TXN_XA_PREPARED        4
#define    TXN_XA_STARTED        5
#define    TXN_XA_SUSPENDED    6
    u_int32_t xa_status;        /* XA status */
    /*
    * XID (xid_t) structure: because these fields are logged, the
    * sizes have to be explicit.
    */
    DB_XID xid;            /* XA global transaction id */
    u_int32_t bqual;        /* bqual_length from XID */
    u_int32_t gtrid;        /* gtrid_length from XID */
    int32_t format;            /* XA format */
} TXN_DETAIL;
</code>
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. 크로스 플레이가 있습니까?
1 몇 달 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

친구들과 wallpaperengine을 공유하는 방법 친구들과 wallpaperengine을 공유하는 방법 Mar 18, 2024 pm 10:00 PM

사용자는 WallpaperEngine을 사용할 때 얻은 배경화면을 친구들과 공유할 수 있습니다. 많은 사용자는 자신이 좋아하는 배경화면을 로컬에 저장한 다음 소셜 소프트웨어를 통해 친구들과 공유할 수 있습니다. wallpaperengine을 친구들과 공유하는 방법 답변: 로컬에 저장하고 친구들과 공유하세요. 1. 좋아하는 배경화면을 로컬에 저장한 다음 소셜 소프트웨어를 통해 친구들과 공유하는 것이 좋습니다. 2. 폴더를 통해 컴퓨터에 업로드한 후 컴퓨터의 창작 워크숍 기능을 사용하여 공유를 클릭할 수도 있습니다. 3. 컴퓨터에서 Wallpaperengine을 사용하고 크리에이티브 워크숍의 옵션 막대를 열고

WeChat Enterprise에서 화면을 공유하는 방법 WeChat Enterprise에서 화면을 공유하는 방법 Feb 28, 2024 pm 12:43 PM

점점 더 많은 기업이 독점 기업 WeChat을 선택하고 있습니다. 이는 기업과 고객, 파트너 간의 의사소통을 촉진할 뿐만 아니라 업무 효율성도 크게 향상시킵니다. Enterprise WeChat에는 풍부한 기능이 있으며 그 중 화면 공유 기능이 매우 인기가 있습니다. 회의 중에 화면을 공유함으로써 참가자들은 콘텐츠를 보다 직관적으로 표시하고 보다 효율적으로 협업할 수 있습니다. 그렇다면 WeChat Enterprise에서 화면을 효율적으로 공유하는 방법은 무엇입니까? 아직 모르는 사용자를 위해 이 튜토리얼 가이드가 도움이 되기를 바랍니다. WeChat Enterprise에서 화면을 공유하는 방법은 무엇입니까? 1. Enterprise WeChat 메인 인터페이스 왼쪽의 파란색 영역에 "컨퍼런스" 아이콘이 표시됩니다. 클릭하면 세 가지 컨퍼런스 모드가 나타납니다.

삼성 휴대폰에서 Quick Share 기능이 작동하지 않음 – 수정 삼성 휴대폰에서 Quick Share 기능이 작동하지 않음 – 수정 Sep 19, 2023 pm 04:25 PM

Quick Share를 사용하면 삼성 사용자가 장치 간에 파일을 전송하는 데 많은 시간을 절약할 수 있습니다. 그러나 삼성 갤럭시 사용자들은 휴대폰의 Quick Share 기능에 문제가 있다는 불만을 제기해 왔습니다. 일반적으로 빠른 공유의 가시성 문제로 인해 이 문제가 발생합니다. 따라서 이것은 Galaxy 장치의 Quick Share 기능 문제를 해결하는 데 필요한 유일한 가이드입니다. 수정 1 - 빠른 공유 가시성 설정 변경 휴대폰에서 빠른 공유 가시성 설정을 전환합니다. Quick Share가 잘못된 설정으로 설정되어 이 문제가 발생할 수 있습니다. 1단계 – 먼저 위로 한 번 스와이프하여 앱 서랍을 엽니다. 2단계 – 설정을 엽니다. 3단계 – 설정 페이지로 이동하여 연결된 장치 탭을 엽니다. 4단계 – “빠른 공유” 기능을 켭니다. 5단계

Windows 11 폴더 공유 가이드: 파일과 데이터를 쉽게 공유 Windows 11 폴더 공유 가이드: 파일과 데이터를 쉽게 공유 Mar 13, 2024 am 11:49 AM

일상 생활과 직장에서 우리는 종종 서로 다른 장치 간에 파일과 폴더를 공유해야 합니다. Windows 11 시스템에는 편리한 폴더 공유 기능이 내장되어 있어 개인 파일의 개인 정보를 보호하면서 동일한 네트워크 내에서 다른 사람들과 필요한 콘텐츠를 쉽고 안전하게 공유할 수 있습니다. 이 기능을 사용하면 개인 정보 유출에 대한 걱정 없이 파일을 간단하고 효율적으로 공유할 수 있습니다. Windows 11 시스템의 폴더 공유 기능을 통해 우리는 보다 편리하게 협력하고, 소통하고 협업할 수 있어 업무 효율성과 생활 편의성이 향상됩니다. 공유 폴더를 성공적으로 구성하려면 먼저 다음 조건을 충족해야 합니다. 공유에 참여하는 모든 장치가 동일한 네트워크에 연결되어 있습니다. 네트워크 검색을 활성화하고 공유를 구성합니다. 대상 장치를 알아라

iPhone iOS 17에서 NameDrop을 사용하는 방법 iPhone iOS 17에서 NameDrop을 사용하는 방법 Sep 22, 2023 pm 11:41 PM

새로운 Apple iPhone15 시리즈 휴대폰이 출시되고 최신 iOS17 모바일 운영 체제가 출시되면서 Apple 기기에 다양한 새로운 기능, 조정 및 개선 사항이 적용되었습니다. 사용자는 iPhone 및 iOS17에서 새로운 NameDrop 기능을 사용하는 방법을 궁금해할 수 있습니다. 이 가이드는 iOS17에서 사용할 수 있는 새로운 NameDrop 시스템을 사용하여 연락처 정보를 빠르고 효율적으로 공유하는 방법에 대한 간략한 개요를 제공합니다. NameDrop은 iPhone 사용자가 자신의 연락처 정보를 다른 사람과 빠르게 공유할 수 있는 기능입니다. 이는 새로운 친구들과 연락처 정보를 교환해야 하는 사교 행사, 비즈니스 미팅 또는 사교 모임을 위한 편리한 도구입니다. 그러나 NameDrop은 새 연락처를 보내는 데에만 작동한다는 점에 유의하는 것이 중요합니다.

공유 프린터를 프린터에 연결할 수 없습니다 공유 프린터를 프린터에 연결할 수 없습니다 Feb 22, 2024 pm 01:09 PM

디지털 시대의 발전과 함께 공유 프린터는 현대 사무 환경에서 없어서는 안 될 부분이 되었습니다. 그러나 때로는 공유 프린터를 프린터에 연결할 수 없는 문제가 발생할 수 있으며, 이는 작업 효율성에 영향을 미칠 뿐만 아니라 일련의 문제를 일으킬 수도 있습니다. 이 문서에서는 공유 프린터가 프린터에 연결할 수 없는 이유와 해결 방법을 살펴보는 것을 목표로 합니다. 공유 프린터가 프린터에 연결할 수 없는 데에는 여러 가지 이유가 있으며, 그 중 가장 일반적인 것은 네트워크 문제입니다. 공유 프린터와 프린터 간의 네트워크 연결이 불안정하거나 중단되는 경우 정상적인 작동이 불가능합니다.

iPhone의 연락처 사진 및 포스터의 개인정보를 보호하는 방법 iPhone의 연락처 사진 및 포스터의 개인정보를 보호하는 방법 Sep 18, 2023 am 10:49 AM

iPhone에서 연락처 사진과 포스터를 볼 수 있는 사람은 누구입니까? Apple은 다른 사람이 전화를 걸거나 메시지를 보낼 때 iPhone에 표시되는 방식을 개인화할 수 있는 옵션을 제공합니다. 옵션에는 미모티콘, 간단한 텍스트 또는 연락처 사진 및 표시 이미지로 효과가 있는 사용자 정의 사진이 포함됩니다. 언제든지 이러한 선택 사항을 자유롭게 변경하고 연락처 카드의 프로필 간에 전환할 수 있습니다. 또한 Apple은 iOS17에서 사진을 보고 액세스하거나 선택한 이미지를 표시할 수 있는 사람을 제어할 수 있는 기능을 제공합니다. 연락처 목록에 저장된 개인과 이를 공유하도록 결정하거나 연락처와 상호 작용할 때마다 메시지가 표시되도록 iPhone을 설정할 수 있습니다. 원하는 경우 이름을 영구적으로 비활성화할 수도 있습니다.

잠금 대기 시간 초과; 트랜잭션 다시 시작 - MySQL 오류 해결 방법: 트랜잭션 대기 시간 초과 잠금 대기 시간 초과; 트랜잭션 다시 시작 - MySQL 오류 해결 방법: 트랜잭션 대기 시간 초과 Oct 05, 2023 am 08:46 AM

Lockwaittimeoutexceeded;tryrestartingtransaction - MySQL 오류 해결 방법: 트랜잭션 대기 시간 초과 MySQL 데이터베이스를 사용할 때 다음과 같은 일반적인 오류가 발생할 수 있습니다. Lockwaittimeoutexceeded;tryrestartingtransaction 이 오류는 트랜잭션 대기 시간이 초과되었음을 나타냅니다. 이 오류는 일반적으로 다음과 같은 경우에 발생합니다.

See all articles