• PostgreSQL在何处处理 sql查询之十八


    接前面,由于看到对 BasicOpenFile 函数的调用。

    自然想到,如果两个进程同时访问一个表(即同一文件),会否有冲突或效率的问题。

    开两个psql客户端,连接数据库后,后台生成两个进程,

    分别运行 select * from tst01 进行观察...发现各进程之间互相不干扰。

    我实验的方法,加入调试代码:

    /*
     * BasicOpenFile --- same as open(2) except can free other FDs if needed
     *
     * This is exported for use by places that really want a plain kernel FD,
     * but need to be proof against running out of FDs.  Once an FD has been
     * successfully returned, it is the caller's responsibility to ensure that
     * it will not be leaked on ereport()!    Most users should *not* call this
     * routine directly, but instead use the VFD abstraction level, which
     * provides protection against descriptor leaks as well as management of
     * files that need to be open for more than a short period of time.
     *
     * Ideally this should be the *only* direct call of open() in the backend.
     * In practice, the postmaster calls open() directly, and there are some
     * direct open() calls done early in backend startup.  Those are OK since
     * this module wouldn't have any open files to close at that point anyway.
     */
    int
    BasicOpenFile(FileName fileName, int fileFlags, int fileMode)
    {
        int            fd;
        //char *tst01=(char *)fileName;
        char *tst02="base/12788/16384"; //tst01 table's file is base/12788/16384
    
    tryAgain:
    
        fd = open(fileName, fileFlags, fileMode);
    
        char *tst01=(char *)fileName;
        fprintf(stderr,"length of fileName is:%d\n",strlen(fileName));
    
        if ( strcmp( fileName, tst02) == 0)
        {
            fprintf(stderr,"Sleeping.....by Process:%d\n",getpid());
            sleep(120);
        }
    
        //fd = open(fileName, fileFlags, fileMode);
    
        if (fd >= 0)
            return fd;                /* success! */
    
        if (errno == EMFILE || errno == ENFILE)
        {
            int            save_errno = errno;
    
            ereport(LOG,
                    (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
                     errmsg("out of file descriptors: %m; release and retry")));
            errno = 0;
            if (ReleaseLruFile())
                goto tryAgain;
            errno = save_errno;
        }
    
        return -1;                    /* failure */
    }

    那么如果同时写入的时候又会如何,这个问题还需进一步地观察代码。

    至少,不同的进程同时读一个表,在文件IO级别,没有发生阻塞。

  • 相关阅读:
    VirtualBox下Ubuntu更改分辨率方法
    Asp.Net防止刷新重复提交数据小记
    耻辱名单新成员,腾讯QQ影音违反开源协议遭谴责
    赛门铁克BERS 2010新增Linux备份还原
    开源邮件服务解决方案 iRedMail0.6.0beta1 发布,支持 FreeBSD
    防止ASP.NET按钮多次提交代码
    与省局网站备案管理系统接口规范试行版文件下载地址
    2010预测:开源ERP难有大作为
    ASP.NET对IIS中的虚拟目录进行操作
    C#三种模拟自动登录和提交POST信息的实现方法
  • 原文地址:https://www.cnblogs.com/gaojian/p/3100075.html
Copyright © 2020-2023  润新知