• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.lock_parent_directory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中swift.common.utils.lock_parent_directory函数的典型用法代码示例。如果您正苦于以下问题:Python lock_parent_directory函数的具体用法?Python lock_parent_directory怎么用?Python lock_parent_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lock_parent_directory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: reclaim

    def reclaim(self, age_timestamp, sync_timestamp):
        """
        Delete rows from the db_contains_type table that are marked deleted
        and whose created_at timestamp is < age_timestamp.  Also deletes rows
        from incoming_sync and outgoing_sync where the updated_at timestamp is
        < sync_timestamp.

        In addition, this calls the DatabaseBroker's :func:`_reclaim` method.

        :param age_timestamp: max created_at timestamp of object rows to delete
        :param sync_timestamp: max update_at timestamp of sync rows to delete
        """
        if self.db_file != ':memory:' and os.path.exists(self.pending_file):
            with lock_parent_directory(self.pending_file,
                                       self.pending_timeout):
                self._commit_puts()
        with self.get() as conn:
            conn.execute('''
                DELETE FROM %s WHERE deleted = 1 AND %s < ?
            ''' % (self.db_contains_type, self.db_reclaim_timestamp),
                (age_timestamp,))
            try:
                conn.execute('''
                    DELETE FROM outgoing_sync WHERE updated_at < ?
                ''', (sync_timestamp,))
                conn.execute('''
                    DELETE FROM incoming_sync WHERE updated_at < ?
                ''', (sync_timestamp,))
            except sqlite3.OperationalError as err:
                # Old dbs didn't have updated_at in the _sync tables.
                if 'no such column: updated_at' not in str(err):
                    raise
            DatabaseBroker._reclaim(self, conn, age_timestamp)
            conn.commit()
开发者ID:bebule,项目名称:swift,代码行数:34,代码来源:db.py


示例2: start

 def start(self):
     """Start up the ring master"""
     self.logger.notice("Ring-Master starting up")
     self.logger.notice("-> Entering ring orchestration loop.")
     while True:
         try:
             self.pause_if_asked()
             if self.in_change_window():
                 for btype in sorted(self.builder_files.keys()):
                     with lock_parent_directory(self.builder_files[btype],
                                                self.lock_timeout):
                         ring_changed = self.orchestration_pass(btype)
                     if ring_changed:
                         sleep(self.recheck_after_change_interval)
                     else:
                         sleep(self.recheck_interval)
             else:
                 self.logger.debug('Not in change window')
                 sleep(60)
         except exceptions.LockTimeout:
             self.logger.exception('Orchestration LockTimeout Encountered')
         except Exception:
             self.logger.exception('Orchestration Error')
             sleep(60)
         sleep(1)
开发者ID:briancline,项目名称:swift-ring-master,代码行数:25,代码来源:ringmasterd.py


示例3: _validate_file

 def _validate_file(self, filename):
     """Validate md5 of file"""
     if self._changed(filename):
         self.logger.debug("updating md5")
         with lock_parent_directory(self.swiftdir, self.lock_timeout):
             self.last_tstamp[filename] = stat(filename).st_mtime
             self.current_md5[filename] = get_md5sum(filename)
开发者ID:pandemicsyn,项目名称:swift-ring-master,代码行数:7,代码来源:ringmasterwsgi.py


示例4: _commit_puts

    def _commit_puts(self, item_list=None):
        """
        Scan for .pending files and commit the found records by feeding them
        to merge_items().

        :param item_list: A list of items to commit in addition to .pending
        """
        if self.db_file == ':memory:' or not os.path.exists(self.pending_file):
            return
        if item_list is None:
            item_list = []
        with lock_parent_directory(self.pending_file, self.pending_timeout):
            self._preallocate()
            if not os.path.getsize(self.pending_file):
                if item_list:
                    self.merge_items(item_list)
                return
            with open(self.pending_file, 'r+b') as fp:
                for entry in fp.read().split(':'):
                    if entry:
                        try:
                            self._commit_puts_load(item_list, entry)
                        except Exception:
                            self.logger.exception(
                                _('Invalid pending entry %(file)s: %(entry)s'),
                                {'file': self.pending_file, 'entry': entry})
                if item_list:
                    self.merge_items(item_list)
                try:
                    os.ftruncate(fp.fileno(), 0)
                except OSError as err:
                    if err.errno != errno.ENOENT:
                        raise
开发者ID:HoO-Group,项目名称:swift,代码行数:33,代码来源:db.py


示例5: main

def main(arguments=None):
    global argv, backup_dir, builder, builder_file, ring_file
    if arguments:
        argv = arguments
    else:
        argv = sys_argv

    if len(argv) < 2:
        print "swift-ring-builder %(MAJOR_VERSION)s.%(MINOR_VERSION)s\n" % \
              globals()
        print Commands.default.__doc__.strip()
        print
        cmds = [c for c, f in Commands.__dict__.iteritems()
                if f.__doc__ and c[0] != '_' and c != 'default']
        cmds.sort()
        for cmd in cmds:
            print Commands.__dict__[cmd].__doc__.strip()
            print
        print parse_search_value.__doc__.strip()
        print
        for line in wrap(' '.join(cmds), 79, initial_indent='Quick list: ',
                         subsequent_indent='            '):
            print line
        print('Exit codes: 0 = operation successful\n'
              '            1 = operation completed with warnings\n'
              '            2 = error')
        exit(EXIT_SUCCESS)

    builder_file, ring_file = parse_builder_ring_filename_args(argv)

    if exists(builder_file):
        builder = RingBuilder.load(builder_file)
    elif len(argv) < 3 or argv[2] not in('create', 'write_builder'):
        print 'Ring Builder file does not exist: %s' % argv[1]
        exit(EXIT_ERROR)

    backup_dir = pathjoin(dirname(argv[1]), 'backups')
    try:
        mkdir(backup_dir)
    except OSError as err:
        if err.errno != EEXIST:
            raise

    if len(argv) == 2:
        command = "default"
    else:
        command = argv[2]
    if argv[0].endswith('-safe'):
        try:
            with lock_parent_directory(abspath(argv[1]), 15):
                Commands.__dict__.get(command, Commands.unknown.im_func)()
        except exceptions.LockTimeout:
            print "Ring/builder dir currently locked."
            exit(2)
    else:
        Commands.__dict__.get(command, Commands.unknown.im_func)()
开发者ID:701,项目名称:swift,代码行数:56,代码来源:ringbuilder.py


示例6: delete_db

 def delete_db(self, object_file):
     hash_dir = os.path.dirname(object_file)
     suf_dir = os.path.dirname(hash_dir)
     with lock_parent_directory(object_file):
         shutil.rmtree(hash_dir, True)
     try:
         os.rmdir(suf_dir)
     except OSError, err:
         if err.errno not in (errno.ENOENT, errno.ENOTEMPTY):
             self.logger.exception(_("ERROR while trying to clean up %s") % suf_dir)
开发者ID:rushikeshjadhav,项目名称:swift,代码行数:10,代码来源:db_replicator.py


示例7: test_ringmaster_validate_locked_dir

 def test_ringmaster_validate_locked_dir(self):
     self._setup_builder_rings()
     rma = RingMasterApp({'swiftdir': self.testdir, 'log_path': self.test_log_path, 'locktimeout': "0.1"})
     for i in rma.current_md5:
         self.assertEquals(rma._changed(i), False)
     self._setup_builder_rings(count=5)
     for i in rma.current_md5:
         t = time.time() - 300
         os.utime(i, (t, t))
     with lock_parent_directory(self.testdir):
         for i in rma.current_md5:
             self.assertRaises(LockTimeout, rma._validate_file, i)
开发者ID:briancline,项目名称:swift-ring-master,代码行数:12,代码来源:test_ringmasterwsgi.py


示例8: _commit_puts_stale_ok

 def _commit_puts_stale_ok(self):
     """
     Catch failures of _commit_puts() if broker is intended for
     reading of stats, and thus does not care for pending updates.
     """
     if self.db_file == ":memory:" or not os.path.exists(self.pending_file):
         return
     try:
         with lock_parent_directory(self.pending_file, self.pending_timeout):
             self._commit_puts()
     except LockTimeout:
         if not self.stale_reads_ok:
             raise
开发者ID:kirubakk,项目名称:swift,代码行数:13,代码来源:db.py


示例9: _commit_puts_stale_ok

 def _commit_puts_stale_ok(self):
     """
     Catch failures of _commit_puts() if broker is intended for
     reading of stats, and thus does not care for pending updates.
     """
     if self._skip_commit_puts():
         return
     try:
         with lock_parent_directory(self.pending_file,
                                    self.pending_timeout):
             self._commit_puts()
     except (LockTimeout, sqlite3.OperationalError):
         if not self.stale_reads_ok:
             raise
开发者ID:mahak,项目名称:swift,代码行数:14,代码来源:db.py


示例10: delete_db

 def delete_db(self, object_file):
     hash_dir = os.path.dirname(object_file)
     suf_dir = os.path.dirname(hash_dir)
     with lock_parent_directory(object_file):
         shutil.rmtree(hash_dir, True)
     try:
         os.rmdir(suf_dir)
     except OSError as err:
         if err.errno not in (errno.ENOENT, errno.ENOTEMPTY):
             self.logger.exception(
                 _('ERROR while trying to clean up %s') % suf_dir)
     self.stats['remove'] += 1
     device_name = self.extract_device(object_file)
     self.logger.increment('removes.' + device_name)
开发者ID:sa4250mnpo70,项目名称:swift,代码行数:14,代码来源:db_replicator.py


示例11: put_object

    def put_object(self, name, timestamp, size, content_type, etag, deleted=0, storage_policy_index=0):
        """
        Creates an object in the DB with its metadata.

        :param name: object name to be created
        :param timestamp: timestamp of when the object was created
        :param size: object size
        :param content_type: object content-type
        :param etag: object etag
        :param deleted: if True, marks the object as deleted and sets the
                        deleted_at timestamp to timestamp
        :param storage_policy_index: the storage policy index for the object
        """
        record = {
            "name": name,
            "created_at": timestamp,
            "size": size,
            "content_type": content_type,
            "etag": etag,
            "deleted": deleted,
            "storage_policy_index": storage_policy_index,
        }
        if self.db_file == ":memory:":
            self.merge_items([record])
            return
        if not os.path.exists(self.db_file):
            raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
        pending_size = 0
        try:
            pending_size = os.path.getsize(self.pending_file)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        if pending_size > PENDING_CAP:
            self._commit_puts([record])
        else:
            with lock_parent_directory(self.pending_file, self.pending_timeout):
                with open(self.pending_file, "a+b") as fp:
                    # Colons aren't used in base64 encoding; so they are our
                    # delimiter
                    fp.write(":")
                    fp.write(
                        pickle.dumps(
                            (name, timestamp, size, content_type, etag, deleted, storage_policy_index),
                            protocol=PICKLE_PROTOCOL,
                        ).encode("base64")
                    )
                    fp.flush()
开发者ID:nagyist,项目名称:swift,代码行数:48,代码来源:backend.py


示例12: put_container

    def put_container(self, name, put_timestamp, delete_timestamp,
                      object_count, bytes_used, storage_policy_index):
        """
        Create a container with the given attributes.

        :param name: name of the container to create
        :param put_timestamp: put_timestamp of the container to create
        :param delete_timestamp: delete_timestamp of the container to create
        :param object_count: number of objects in the container
        :param bytes_used: number of bytes used by the container
        :param storage_policy_index:  the storage policy for this container
        """
        if delete_timestamp > put_timestamp and \
                object_count in (None, '', 0, '0'):
            deleted = 1
        else:
            deleted = 0
        record = {'name': name, 'put_timestamp': put_timestamp,
                  'delete_timestamp': delete_timestamp,
                  'object_count': object_count,
                  'bytes_used': bytes_used,
                  'deleted': deleted,
                  'storage_policy_index': storage_policy_index}
        if self.db_file == ':memory:':
            self.merge_items([record])
            return
        if not os.path.exists(self.db_file):
            raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
        pending_size = 0
        try:
            pending_size = os.path.getsize(self.pending_file)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        if pending_size > PENDING_CAP:
            self._commit_puts([record])
        else:
            with lock_parent_directory(self.pending_file,
                                       self.pending_timeout):
                with open(self.pending_file, 'a+b') as fp:
                    # Colons aren't used in base64 encoding; so they are our
                    # delimiter
                    fp.write(':')
                    fp.write(pickle.dumps(
                        (name, put_timestamp, delete_timestamp, object_count,
                         bytes_used, deleted, storage_policy_index),
                        protocol=PICKLE_PROTOCOL).encode('base64'))
                    fp.flush()
开发者ID:7yue,项目名称:swift,代码行数:48,代码来源:backend.py


示例13: put_container

    def put_container(self, name, put_timestamp, delete_timestamp, object_count, bytes_used):
        """
        Create a container with the given attributes.

        :param name: name of the container to create
        :param put_timestamp: put_timestamp of the container to create
        :param delete_timestamp: delete_timestamp of the container to create
        :param object_count: number of objects in the container
        :param bytes_used: number of bytes used by the container
        """
        if delete_timestamp > put_timestamp and object_count in (None, "", 0, "0"):
            deleted = 1
        else:
            deleted = 0
        record = {
            "name": name,
            "put_timestamp": put_timestamp,
            "delete_timestamp": delete_timestamp,
            "object_count": object_count,
            "bytes_used": bytes_used,
            "deleted": deleted,
        }
        if self.db_file == ":memory:":
            self.merge_items([record])
            return
        if not os.path.exists(self.db_file):
            raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
        pending_size = 0
        try:
            pending_size = os.path.getsize(self.pending_file)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        if pending_size > PENDING_CAP:
            self._commit_puts([record])
        else:
            with lock_parent_directory(self.pending_file, self.pending_timeout):
                with open(self.pending_file, "a+b") as fp:
                    # Colons aren't used in base64 encoding; so they are our
                    # delimiter
                    fp.write(":")
                    fp.write(
                        pickle.dumps(
                            (name, put_timestamp, delete_timestamp, object_count, bytes_used, deleted),
                            protocol=PICKLE_PROTOCOL,
                        ).encode("base64")
                    )
                    fp.flush()
开发者ID:anishnarang,项目名称:gswift-multinode,代码行数:48,代码来源:backend.py


示例14: dump_builder

    def dump_builder(self):
        """Write out new builder files

        :param builder: The builder to dump
        :builder_file: The builder file to write to
        """
        with lock_parent_directory(self.builder_file, 15):
            bfile, bmd5 = self._make_backup()
            print "Backed up %s to %s (%s)" % (self.builder_file, bfile, bmd5)
            fd, tmppath = mkstemp(
                dir=dirname(self.builder_file), suffix='.tmp.builder')
            pickle.dump(self.builder.to_dict(), fdopen(fd, 'wb'), protocol=2)
            rename(tmppath, self.builder_file)
        print "Success. %s updated. (%s)" % (
            self.builder_file, self.get_md5sum(self.builder_file))
        print "Rebalance still required."
开发者ID:pandemicsyn,项目名称:swiftscout,代码行数:16,代码来源:drivescout.py


示例15: put_container

    def put_container(self, name, put_timestamp, delete_timestamp, object_count, bytes_used):
        """
        Create a container with the given attributes.

        :param name: name of the container to create
        :param put_timestamp: put_timestamp of the container to create
        :param delete_timestamp: delete_timestamp of the container to create
        :param object_count: number of objects in the container
        :param bytes_used: number of bytes used by the container
        """
        if delete_timestamp > put_timestamp and object_count in (None, "", 0, "0"):
            deleted = 1
        else:
            deleted = 0
        record = {
            "name": name,
            "put_timestamp": put_timestamp,
            "delete_timestamp": delete_timestamp,
            "object_count": object_count,
            "bytes_used": bytes_used,
            "deleted": deleted,
        }
        if self.db_file == ":memory:":
            self.merge_items([record])
            return
        commit = False
        with lock_parent_directory(self.pending_file, self.pending_timeout):
            with open(self.pending_file, "a+b") as fp:
                # Colons aren't used in base64 encoding; so they are our
                # delimiter
                fp.write(":")
                fp.write(
                    pickle.dumps(
                        (name, put_timestamp, delete_timestamp, object_count, bytes_used, deleted),
                        protocol=PICKLE_PROTOCOL,
                    ).encode("base64")
                )
                fp.flush()
                if fp.tell() > PENDING_CAP:
                    commit = True
        if commit:
            self._commit_puts()
开发者ID:github-lmp,项目名称:zft,代码行数:42,代码来源:db_broker_test.py


示例16: _commit_puts

 def _commit_puts(self, item_list=None):
     """Handles commiting rows in .pending files."""
     if self.db_file == ":memory:" or not os.path.exists(self.pending_file):
         return
     if item_list is None:
         item_list = []
     with lock_parent_directory(self.pending_file, self.pending_timeout):
         self._preallocate()
         if not os.path.getsize(self.pending_file):
             if item_list:
                 self.merge_items(item_list)
             return
         with open(self.pending_file, "r+b") as fp:
             for entry in fp.read().split(":"):
                 if entry:
                     try:
                         (name, put_timestamp, delete_timestamp, object_count, bytes_used, deleted) = pickle.loads(
                             entry.decode("base64")
                         )
                         item_list.append(
                             {
                                 "name": name,
                                 "put_timestamp": put_timestamp,
                                 "delete_timestamp": delete_timestamp,
                                 "object_count": object_count,
                                 "bytes_used": bytes_used,
                                 "deleted": deleted,
                             }
                         )
                     except Exception:
                         self.logger.exception(
                             _("Invalid pending entry %(file)s: %(entry)s"),
                             {"file": self.pending_file, "entry": entry},
                         )
             if item_list:
                 self.merge_items(item_list)
             try:
                 os.ftruncate(fp.fileno(), 0)
             except OSError, err:
                 if err.errno != errno.ENOENT:
                     raise
开发者ID:github-lmp,项目名称:zft,代码行数:41,代码来源:db_broker_test.py


示例17: put_object

    def put_object(self, name, timestamp, size, content_type, etag,
                   deleted=0, metadata=None):
        """
        Creates an object in the DB with its metadata.

        :param name: object name to be created
        :param timestamp: timestamp of when the object was created
        :param size: object size
        :param content_type: object content-type
        :param etag: object etag
        :param deleted: if True, marks the object as deleted and sets the
                        deteleted_at timestamp to timestamp
        """
        record = {'name': name, 'created_at': timestamp, 'size': size,
                  'content_type': content_type, 'etag': etag,
                  'metadata': metadata, 'deleted': deleted}
        if self.db_file == ':memory:':
            self.merge_items([record])
            return
        if not os.path.exists(self.db_file):
            raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
        pending_size = 0
        try:
            pending_size = os.path.getsize(self.pending_file)
        except OSError as err:
            if err.errno != errno.ENOENT:
                raise
        if pending_size > PENDING_CAP:
            self._commit_puts([record])
        else:
            with lock_parent_directory(self.pending_file,
                                       self.pending_timeout):
                with open(self.pending_file, 'a+b') as fp:
                    # Colons aren't used in base64 encoding; so they are our
                    # delimiter
                    fp.write(':')
                    fp.write(pickle.dumps(
                        (name, timestamp, size, content_type, etag, deleted,
                         metadata),
                        protocol=PICKLE_PROTOCOL).encode('base64'))
                    fp.flush()
开发者ID:pkit,项目名称:zwift,代码行数:41,代码来源:server.py


示例18: put_record

    def put_record(self, record):
        """
        Put a record into the DB. If the DB has an associated pending file with
        space then the record is appended to that file and a commit to the DB
        is deferred. If the DB is in-memory or its pending file is full then
        the record will be committed immediately.

        :param record: a record to be added to the DB.
        :raises DatabaseConnectionError: if the DB file does not exist or if
            ``skip_commits`` is True.
        :raises LockTimeout: if a timeout occurs while waiting to take a lock
            to write to the pending file.
        """
        if self._db_file == ':memory:':
            self.merge_items([record])
            return
        if not os.path.exists(self.db_file):
            raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
        if self.skip_commits:
            raise DatabaseConnectionError(self.db_file,
                                          'commits not accepted')
        with lock_parent_directory(self.pending_file, self.pending_timeout):
            pending_size = 0
            try:
                pending_size = os.path.getsize(self.pending_file)
            except OSError as err:
                if err.errno != errno.ENOENT:
                    raise
            if pending_size > PENDING_CAP:
                self._commit_puts([record])
            else:
                with open(self.pending_file, 'a+b') as fp:
                    # Colons aren't used in base64 encoding; so they are our
                    # delimiter
                    fp.write(b':')
                    fp.write(base64.b64encode(pickle.dumps(
                        self.make_tuple_for_pickle(record),
                        protocol=PICKLE_PROTOCOL)))
                    fp.flush()
开发者ID:mahak,项目名称:swift,代码行数:39,代码来源:db.py


示例19: reclaim

    def reclaim(self, age_timestamp, sync_timestamp):
        """
        Delete reclaimable rows and metadata from the db.

        By default this method will delete rows from the db_contains_type table
        that are marked deleted and whose created_at timestamp is <
        age_timestamp, and deletes rows from incoming_sync and outgoing_sync
        where the updated_at timestamp is < sync_timestamp. In addition, this
        calls the :meth:`_reclaim_metadata` method.

        Subclasses may reclaim other items by overriding :meth:`_reclaim`.

        :param age_timestamp: max created_at timestamp of object rows to delete
        :param sync_timestamp: max update_at timestamp of sync rows to delete
        """
        if not self._skip_commit_puts():
            with lock_parent_directory(self.pending_file,
                                       self.pending_timeout):
                self._commit_puts()
        with self.get() as conn:
            self._reclaim(conn, age_timestamp, sync_timestamp)
            self._reclaim_metadata(conn, age_timestamp)
            conn.commit()
开发者ID:mahak,项目名称:swift,代码行数:23,代码来源:db.py


示例20: put_record

 def put_record(self, record):
     if self.db_file == ':memory:':
         self.merge_items([record])
         return
     if not os.path.exists(self.db_file):
         raise DatabaseConnectionError(self.db_file, "DB doesn't exist")
     with lock_parent_directory(self.pending_file, self.pending_timeout):
         pending_size = 0
         try:
             pending_size = os.path.getsize(self.pending_file)
         except OSError as err:
             if err.errno != errno.ENOENT:
                 raise
         if pending_size > PENDING_CAP:
             self._commit_puts([record])
         else:
             with open(self.pending_file, 'a+b') as fp:
                 # Colons aren't used in base64 encoding; so they are our
                 # delimiter
                 fp.write(':')
                 fp.write(pickle.dumps(
                     self.make_tuple_for_pickle(record),
                     protocol=PICKLE_PROTOCOL).encode('base64'))
                 fp.flush()
开发者ID:bebule,项目名称:swift,代码行数:24,代码来源:db.py



注:本文中的swift.common.utils.lock_parent_directory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.lock_path函数代码示例发布时间:2022-05-27
下一篇:
Python utils.list_from_csv函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap