PostgreSQL V9.6 ExclusiveLock的用途

1 创建劝告锁

pg_advisory_lock_int8(PG_FUNCTION_ARGS) //在指定对象上加派他式的劝告锁

{...

            SET_LOCKTAG_INT64(tag, key);

            (void) LockAcquire(&tag, ExclusiveLock, true, false);

...}

2 对于诸如VACUUM类似的操作在指定对象上加排它锁

btvacuumscan(...)

{...

    for (;;)

    {

        /* Get the current relation length */

        if (needLock)

            LockRelationForExtension(rel, ExclusiveLock);

        num_pages = RelationGetNumberOfBlocks(rel);

        if (needLock)

            UnlockRelationForExtension(rel, ExclusiveLock);

...

   }

...

}

3 为系统表加锁

replorigin_create(char *roname)

{...

    rel = heap_open(ReplicationOriginRelationId, ExclusiveLock); // ReplicationOriginRelationIdpg_replication_origin系统表的标识

...}

4 为对象加锁

GetLockStatusData(void)

{...

    for (i = 0; i < ProcGlobal->allProcCount; ++i)

    {...

        for (f = 0; f < FP_LOCK_SLOTS_PER_BACKEND; ++f)

        {

            LockInstanceData *instance;

...

            instance = &data->locks[el];

            SET_LOCKTAG_RELATION(instance->locktag, proc->databaseId, proc->fpRelId[f]);

            instance->holdMask = LOCKBIT_ON(ExclusiveLock);

...

        }

...

    }

...

}

    其中,LockInstanceData定义如下:

typedef struct LockInstanceData

{

    LOCKTAG    locktag;  /* 被加锁的对象的标识 */

    LOCKMASK          holdMask;  /* locks held by this PGPROC,值为“LOCKBIT_ON(ExclusiveLock)”表示被加锁 */

    LOCKMODE waitLockMode;  /* lock awaited by this PGPROC, if any */

    BackendId            backend;  /* backend ID of this PGPROC */

    LocalTransactionId lxid;  /* local transaction ID of this PGPROC */

    int    pid;  /* pid of this PGPROC */

    int    leaderPid;  /* pid of group leader; = pid if no group */

    bool    fastpath;  /* taken via fastpath? */

} LockInstanceData;

5 为指定的Relation加锁(物理页面在缓存区的页)

RelationGetBufferForTuple(Relation relation, ...) //返回被pin住的且被排它锁锁住的buf

{...

    if (needLock)

    {

        if (!use_fsm)

            LockRelationForExtension(relation, ExclusiveLock);

        else if (!ConditionalLockRelationForExtension(relation, ExclusiveLock))

        {

            /* Couldn't get the lock immediately; wait for it. */

            LockRelationForExtension(relation, ExclusiveLock); //relation上加派他锁

...

            /*

             * If some other waiter has already extended the relation, we

             * don't need to do so; just use the existing freespace.

             */

            if (targetBlock != InvalidBlockNumber)

            {

                UnlockRelationForExtension(relation, ExclusiveLock);

                goto loop;

            }

...

        }

    }

...

}

6 为索引页加锁

ginInsertCleanup(GinState *ginstate, ...) //为指定的索引页加锁,本质上类似于为指定的Relation加锁

{

    Relation          index = ginstate->index; //一个index页,也是一个被“Relation”定义的对象

    if (inVacuum)

    {

        /*

         * We are called from [auto]vacuum/analyze or

         * gin_clean_pending_list() and we would like to wait

         * concurrent cleanup to finish.

         */

        LockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock); //为指定的索引页加派他锁

...

    }

    else

    {

        /*

         * We are called from regular insert and if we see

         * concurrent cleanup just exit in hope that concurrent

         * process will clean up pending list.

         */

        if (!ConditionalLockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock))

            return;

...

    }

...

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.JLink-v9_bootloader固件.bootloader.bin 2.JLINK9可升级固件及固件更新工具.JlinkV9.3原理图.pdf jlink-v9.5原理图.pdf J-LINK-V9-bootloader.dfu jlink-v9激活.txt 详细操作步骤说明.docx ST_DfuSe_Demo_V3.0.6_Setup.zip 3.升级方式:DFU ISP(通过boot引脚设置从system memory启动)。 工具:ST官方工具,ST_DfuSe_Demo_V3.0.6。 硬件:JLink V9.x硬件为stm32f205rc. 操作步骤: 1. 参考JLink V9.3或JLink V9.5原理图(注意:原理图和你手上实物可能不是100%一致。)。通过boot引脚设置从system memory启动: 设置stm32f205rc的引脚电平为boot0:1,boot1:0(如果原硬件JLink上无跳线帽,需要自己手动焊线设置电平),使上电后,进入system memory。 下图是我的JLink V9.3, boot0引脚,PCB上直接连接到GND上了,用美工刀片挑起这个引脚,再焊线的。Boot1引脚,在原理图中,连接在200欧姆的排阻上,我是从排阻上焊线的。由于从网上下载了4份资料,需要反复测试,反复焊线设置启动方式,太麻烦了,后面加焊了排针,使用了杜邦线。 2. 安装ST_DfuSe_Demo_V3.0.6,驱动不会自动安装,需要自己更新驱动。把JLink 通过USB线插到电脑上,在设备管理器中,会显示未知驱动设备,手动浏览到ST_DfuSe_Demo_V3.0.6的安装路径(如:C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.6\Bin\Driver\Win7\x64),即可完成驱动安装。 3. 运行DfuSeDemo, 4.点击Choose, 选择文件J-LINK-V9-bootloader.dfu,点击Upgrade,开始更新。 5.拔掉USB线,恢复启动引脚电平boot0:0,boot1:x(这个脚是JTAG的数据线引脚,取消接地即可)。插上USB线,打开JLink.exe,提示升级,成功后,即为最新版本(我的JFlash版本为JLink_V634f,升级后版本为: firmware: J-Link V9 compiled Aug 23 2018 09:45:44,Hardware version:V9.20.)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值