WO2014048176A1 - 一种对资源进行同步控制的方法、设备和系统 - Google Patents

一种对资源进行同步控制的方法、设备和系统 Download PDF

Info

Publication number
WO2014048176A1
WO2014048176A1 PCT/CN2013/081296 CN2013081296W WO2014048176A1 WO 2014048176 A1 WO2014048176 A1 WO 2014048176A1 CN 2013081296 W CN2013081296 W CN 2013081296W WO 2014048176 A1 WO2014048176 A1 WO 2014048176A1
Authority
WO
WIPO (PCT)
Prior art keywords
terminal
server
resource file
resource
lock
Prior art date
Application number
PCT/CN2013/081296
Other languages
English (en)
French (fr)
Inventor
沈武魁
徐盎
徐伟
许文英
李星
张国勇
Original Assignee
腾讯科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Priority to US14/431,643 priority Critical patent/US9380109B2/en
Publication of WO2014048176A1 publication Critical patent/WO2014048176A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1029Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers using data related to the state of servers by a load balancer
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1031Controlling of the operation of servers by a load balancer, e.g. adding or removing servers that serve requests
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 

Definitions

  • the present invention relates to the field of information synchronization control, and in particular, to a method, device and system for synchronously controlling resources.
  • the information synchronization control scheme provided is that after the producer prepares the resource, the resource file is sent to the file system or the resource record is inserted into the database; the consumer detects the resource file in the file system or detects the resource in the database. Records to confirm that the producer has prepared the resource and then obtained resources from the producer.
  • the database establishes a table corresponding to the inserted resource record, and the server also adjusts the running program according to the inserted resource record, which increases the workload of the device.
  • consumers' access to resources is untimed. Consumers can obtain resources at any time. If consumers acquire resources while producers are also updating resources, this will create read-write conflicts that affect the system. stability.
  • Embodiments of the present invention provide a method, device, and system for synchronously controlling resources, which solves the problem of read and write conflicts between a producer update resource file and a consumer acquired resource file.
  • a method for synchronously controlling a resource, involving a server side includes: the server acquiring an address of the first terminal;
  • the server establishes a first terminal list, where the first terminal list records an address of the first terminal;
  • the server After the server receives the completed resource update notification message sent by the second terminal, setting an empty state for the first terminal in the first terminal list, so that the first terminal is in the first When the first terminal of a terminal list is in an empty state, The second terminal acquires a resource file;
  • the server cancels the clear state of the first terminal in the first terminal list according to the notification of the first terminal.
  • a method for synchronously controlling a resource, involving a first terminal side includes: the first terminal queries a server, whether the first terminal in the first terminal list is in an empty state, where the first terminal list records the The address of the first terminal;
  • the first terminal When the first terminal is in an empty state, the first terminal obtains a resource file from the second terminal;
  • the first terminal After acquiring the resource file, the first terminal notifies the server to cancel the clearing state of the first terminal in the first terminal list.
  • a method for synchronously controlling resources, involving a second terminal side includes: after completing the update of the resource file, the second terminal sends a completed resource update notification message to the server, so that the server is in the first terminal list.
  • the first terminal is set to clear the state.
  • a server comprising:
  • An address obtaining unit configured to acquire an address of the first terminal
  • a list establishing unit configured to establish a first terminal list, where the first terminal list records an address of the first terminal
  • a receiving unit configured to receive a completed resource update notification message sent by the second terminal, where the completed resource update notification message is sent by the second terminal after updating the resource file;
  • a setting unit configured to: after receiving the completed resource update notification message sent by the second terminal, set an empty state for the first terminal in the first terminal list, so that the first terminal is in the When the first terminal of the first terminal list is in an empty state, acquiring a resource file to the second terminal;
  • a first canceling unit configured to cancel, after the first terminal acquires the resource file, the clearing status of the first terminal in the first terminal list according to the notification of the first terminal.
  • a first terminal includes:
  • a querying unit configured to query, by the server, whether the first terminal in the first terminal list is in an empty state, where the first terminal list records an address of the first terminal
  • a resource file obtaining unit configured to: when the first terminal is in an empty state, the first A terminal acquires a resource file from the second terminal;
  • a second canceling unit configured to notify the server to cancel the clearing state of the first terminal in the first terminal list after acquiring the resource file.
  • a second terminal includes:
  • the resource update notification unit is configured to send a completed resource update notification message to the server after completing the update of the resource file, so that the server sets an empty state for the first terminal in the first terminal list.
  • a system for synchronously controlling resources comprising: the server according to any one of the preceding items, a first terminal, and a second terminal.
  • a method, device, and system for synchronously controlling a resource according to an embodiment of the present invention, the second terminal notifying the server after the resource file is updated, where the server is the first terminal in the first terminal list Setting an empty state to indicate that the second terminal has completed the resource file update, without the second terminal inserting a resource record into the database to notify the first terminal resource that the update has been completed, and also avoiding that the server is running according to the inserted resource record pair.
  • the program is adjusted.
  • FIG. 1 is a flowchart of a server side of a method for synchronously controlling resources according to Embodiment 1 of the present invention
  • FIG. 2 is a flowchart of a first terminal side of a method for synchronously controlling resources according to Embodiment 1 of the present invention
  • FIG. 3 is a flowchart of a method for synchronously controlling resources according to Embodiment 2 of the present invention.
  • FIG. 4 is a flowchart of a second terminal performing resource file update according to a method for synchronously controlling resources according to Embodiment 2 of the present invention
  • FIG. 5 is a flowchart of a first terminal acquiring a resource file according to a method for synchronously controlling resources according to Embodiment 2 of the present invention
  • FIG. 6 is a block diagram of a server according to Embodiment 3 of the present invention.
  • FIG. 7 is a block diagram of another server according to Embodiment 3 of the present invention.
  • FIG. 8 is a block diagram of another server according to Embodiment 3 of the present invention.
  • FIG. 9 is a block diagram of a first terminal according to Embodiment 3 of the present invention.
  • FIG. 10 is a block diagram of another first terminal according to Embodiment 3 of the present invention
  • FIG. 1 is a block diagram of another first terminal according to Embodiment 3 of the present invention
  • FIG. 12 is a block diagram of another second terminal according to Embodiment 3 of the present invention
  • FIG. 13 is another block diagram of a second terminal according to Embodiment 3 of the present invention.
  • FIG. 14 is a schematic diagram of a system for synchronously controlling resources according to Embodiment 3 of the present invention.
  • the application scenario of the embodiment of the present invention includes a server, a first terminal, and a second terminal.
  • the first terminal may be specifically a terminal operated by a consumer
  • the second terminal may be The terminal operated by the producer.
  • the resource file is stored in the second terminal, and the first terminal needs to acquire the resource file in the second terminal.
  • the server simultaneously connects the second terminal and the first terminal.
  • the embodiment of the invention provides a method for synchronously controlling resources, which is related to the server side. As shown in FIG. 1, the method includes:
  • the server acquires the address of the first terminal.
  • the server Before the first terminal acquires the resource file, the server establishes a first terminal list, and the address of the first terminal is recorded in the first terminal list.
  • the second terminal After the second terminal updates the resource file, it sends a completed resource update notification message to the server.
  • the server After the server receives the completed resource update notification message sent by the second terminal, setting an empty state for the address of the first terminal in the first terminal list, so that the first terminal is in the first terminal.
  • the address of the first terminal in the list is in the empty state, Obtaining a resource file from the second terminal.
  • the clearing state is set for the address of the first terminal in the first terminal list, and specifically, the address of the first terminal in the first terminal list is deleted, so that the first terminal is in the first When the address of the first terminal in a terminal list is deleted, the resource file is obtained from the second terminal.
  • the first terminal After the first terminal obtains the resource file, it notifies the server that the resource file is obtained, and after the server receives the notification, cancels the clearing state of the address of the first terminal in the first terminal list.
  • the clearing of the address of the first terminal in the first terminal list may be cancelled. Specifically, the address of the first terminal may be re-added to the first terminal list.
  • the server obtains the addresses of the respective first terminals, and stores the obtained addresses of the first terminals in the first terminal list. After that, when the second terminal completes the resource update, the completed resource update message will be sent to the server. After receiving the completed resource update notification message, the server sets the clear state for the address of the first terminal in the first terminal list.
  • the server sets the clear state for the address of the first terminal in the first terminal list.
  • the second terminal notifies the server of the resource file update completion, and the server sets the clear state for the address of the first terminal to indicate that the second terminal has completed the resource file update, without the second terminal
  • the database inserts a resource record to inform that the first terminal resource has been updated, and also prevents the server from adjusting the running program according to the inserted resource record.
  • the embodiment of the present invention further provides a method for synchronously controlling a resource, which is related to a first terminal side. As shown in FIG. 2, the method includes:
  • the first terminal Before obtaining the resource file, the first terminal first queries whether the address of the first terminal in the first list is in an empty state, and determines whether the address of the first terminal in the first list is an empty state. Whether the resource file is updated or not, and then the resource file is acquired. When the address of the first terminal in the first terminal list is in an empty state, Step 202 is performed, otherwise the resource file acquisition action is not performed.
  • the address of the first terminal in the first terminal list is in an empty state, indicating that the second terminal has updated the resource file, and the first terminal may obtain the resource file from the second terminal.
  • the server is notified to cancel the clearing state of the address of the first terminal in the first terminal list.
  • the first terminal After the first terminal acquires the resource file, the first terminal notifies the server to cancel the clearing state of the address of the first terminal in the first terminal list, to indicate that the first terminal has already used resources. File acquisition.
  • the second terminal after completing the update of the resource file, the second terminal sends a completed resource update notification message to the server, so that the server sets the address of the first terminal in the first terminal list. Empty the status.
  • the embodiment of the invention provides a method for synchronously controlling resources, and the method further includes:
  • the server acquires the address of the first terminal, the address of the second terminal, and the address of the resource file in the second terminal. After the address is acquired, the server establishes the first terminal list, and the first terminal The terminal address is stored in the first list. After receiving the completed resource update notification message sent by the second terminal, the server sets the address of the first terminal in the first terminal list to the clear state. .
  • the first terminal queries the first terminal list, and when the address of the first terminal in the first terminal list is in an empty state, the server acquires an address of the resource file by using the second terminal, The first terminal acquires a resource file from the second terminal by using an address of the resource file. After the first terminal acquires the resource file, the server cancels the clearing state of the address of the first terminal in the first terminal list according to the notification of the first terminal.
  • An embodiment of the present invention provides a method for synchronously controlling a resource, where the second terminal notifies the server after the resource file is updated, and the server sets the clear state of the address of the first terminal in the first terminal list.
  • the database needs to establish a resource record corresponding to the insertion. The recorded form, the amount of work added by the server to adjust the running program based on the inserted resource record.
  • the embodiment of the invention provides a method for synchronously controlling resources. As shown in FIG. 3, the method includes:
  • the server acquires an address of the first terminal.
  • the server also acquires the address of the resource file stored in the second terminal from the second terminal.
  • the server establishes a first terminal list, where the first terminal list records an address of the first terminal.
  • the server receives the completed resource update notification message sent by the second terminal.
  • the completed resource update notification message is sent by the second terminal after the update of the resource file is completed.
  • the server records an address of the second terminal that has completed the resource update notification message.
  • the first terminal is configured to obtain the second terminal and obtain the resource file by using the address of the second terminal recorded by the server.
  • the first terminal When detecting, by the first terminal, that the address of the first terminal in the first terminal list is in an empty state, the first terminal acquires a resource file from the second terminal.
  • the clearing state is set for the address of the first terminal in the first terminal list, and specifically, the address of the first terminal in the first terminal list is deleted, so that the first terminal is in the first When the address of the first terminal in a terminal list is deleted, the resource file is obtained from the second terminal.
  • the first terminal acquires a resource file from the second terminal when the address of the first terminal is in an empty state.
  • the address of the second terminal and the address of the resource file may be obtained from the server before the first terminal acquires the resource file from the second terminal.
  • the first terminal After obtaining the resource file, the first terminal notifies the server to cancel the clearing state of the address of the first terminal. It should be noted that the clearing of the address of the first terminal in the first terminal list may be cancelled. Specifically, the address of the first terminal may be re-added to the first terminal list.
  • the server In the initial state of the system, the server first obtains the addresses of all the first terminals and stores them in the first terminal list. At the same time, the server also obtains the address of the resource file from the second terminal. After that, on the one hand, the second terminal updates the resource file, and on the other hand, the first terminal acquires the resource file from the second terminal. Assuming that the second terminal A performs an update of the resource file, A will send a completed resource update notification message to the server, and the server records the address of A and sets the clear state for the address of the first terminal of the first terminal list.
  • first terminal here assumed to be the first terminal B
  • B first check whether the address of the first terminal in the server is in the empty state. Since the address of B in the first terminal list is cleared, B obtains the address of A and the address of the resource file from the server, so that the resource file can be obtained from A. After the resource file is obtained, B sends a notification to the server to cause the server to cancel the emptying of the address of B. If the address of B is set to the empty state again, B will read the resource file in A again. If the address of B is not in the first terminal list, it indicates that A has not updated the resource file again, and B will abort. The acquisition action of the resource file.
  • the second terminal notifies the server of the resource file update completion, and the server sets the address of the first terminal to be in an empty state, indicating that the second terminal has updated the resource file,
  • the terminal may obtain the resource file from the second terminal, and after obtaining the resource file, notify the server to cancel the clearing state of the address of the first terminal.
  • the second terminal does not need to insert a resource record into the database to notify the first terminal resource that the update has been completed, and also prevents the server from adjusting the running program according to the inserted resource record, thereby improving the scalability of the system. And improve the stability of the system operation.
  • Zookeepe r is a target
  • a reliable coordination system for large distributed systems, zookeeper has a lock file feature.
  • the user terminal can use the zookeepe r system to create a read lock and a write lock to lock the file.
  • the user terminal first creates a write lock to lock the file, any other The user terminal cannot update and read the file.
  • a read lock is locked to the file, the user terminal can read the file but cannot update the file.
  • the embodiment of the present invention is based on zookeeper.
  • a set of synchronous control systems for service development, using the lock feature of zookeepe r in the embodiment of the present invention is specifically:
  • a method of creating a write lock and updating the resource file according to the write lock includes the following steps:
  • the second terminal creates a write lock before updating the resource file.
  • the server sequentially numbers the locks in the order in which the locks are created, and stores them in the lock H record.
  • the locks stored in the lock directory are numbered sequentially from small to large in the order in which they were created.
  • the lock stored in the lock directory includes a write lock created by the second terminal and a read lock created by the first terminal.
  • the server determines whether there is a lock smaller than a write lock number sent by the second terminal.
  • the server determines that there is no write lock number or a read lock number that is smaller than a write lock number sent by the second terminal, notify the second terminal to update the resource file.
  • the server After the server finishes updating the resource file, the server deletes the write lock corresponding to the second terminal in the lock directory.
  • the second terminal After completing the update of the resource file, the second terminal notifies the server to delete the write lock corresponding to the second terminal, and sends a completed resource update notification message to the server, so that the server is in the first terminal list.
  • the address of the first terminal is set to the clear state.
  • a method of creating a read lock and acquiring the resource file according to the read lock includes the following steps:
  • the server sequentially numbers the locks in the order in which the locks are created, and stores them in the lock directory.
  • the locks stored in the lock directory are numbered sequentially from small to large in the order in which they were created.
  • the lock stored in the lock directory includes a write lock created by the second terminal and a read lock created by the first terminal.
  • the server determines whether there is a write lock smaller than a read lock number sent by the first terminal.
  • the server determines that there is no write lock smaller than the read lock number sent by the first terminal, notify the first terminal to acquire the resource file from the second terminal.
  • the suspension When there is a write lock smaller than the read lock number sent by the first terminal, the suspension will be suspended. A terminal acquires a resource file.
  • the server deletes the read lock corresponding to the first terminal in the lock directory.
  • the first terminal After completing the obtaining of the resource file, the first terminal notifies the server that the resource file is obtained, so that the server deletes the read lock corresponding to the first terminal, and notifies the server to cancel the clearing state of the address of the first terminal.
  • the second terminal creates a write lock before updating the resource file
  • the first terminal creates a read lock before acquiring the resource file
  • the server sequentially numbers the locks by storing the locks and stores the locks in the lock directory.
  • the server determines whether there is a lock smaller than the write lock number sent by the second terminal or whether there is a A write lock with a smaller read lock number sent by the terminal to inform the second terminal whether the resource file can be updated or whether the first terminal can retrieve the resource file.
  • a server provided by the embodiment of the present invention, as shown in FIG. 6, includes:
  • the address obtaining unit 601 is configured to obtain an address of the first terminal.
  • the list establishing unit 602 is configured to establish a first terminal list, where the first terminal list records an address of the first terminal.
  • the receiving unit 603 is configured to receive the completed resource update notification message sent by the second terminal, where the completed resource update notification message is sent by the second terminal to complete the update of the resource file.
  • the setting unit 604 is configured to: after receiving the completed resource update notification message sent by the second terminal, set an empty state for the address of the first terminal in the first terminal list, to facilitate the first terminal. When the address of the first terminal in the first terminal list is in an empty state, the resource file is obtained from the second terminal.
  • the first canceling unit 605 is configured to cancel, after the first terminal acquires the resource file, the clearing state of the address of the first terminal in the first terminal list according to the notification of the first terminal.
  • the server as shown in FIG. 7, further includes:
  • the lock receiving unit 606 is configured to receive a write lock created by the second terminal, where the write lock is created by the second terminal before the update of the resource file, and is further configured to receive the read lock created by the first terminal; The read lock is created before the first terminal acquires a resource file from the second terminal.
  • the server further includes:
  • the numbering unit 607 is used to sequentially number the locks in the order of creation and store them in the lock directory.
  • the notifying unit 608 is configured to notify the second terminal to update the resource file when there is no write lock number or read lock number smaller than the write lock number sent by the second terminal; When the write lock number smaller than the read lock number sent by the first terminal does not exist, the first terminal is notified to acquire the resource file.
  • a deleting unit 609 configured to delete a write lock corresponding to the second terminal in the lock directory after the second terminal completes the update of the resource file; the deleting unit is further configured to be in the first terminal After the resource file acquisition is completed, the read lock corresponding to the first terminal is deleted in the lock directory.
  • the server further includes:
  • the recording unit 610 is configured to record, after the server receives the completed resource update notification message sent by the second terminal, the address of the second terminal of the completed resource update notification message.
  • the resource file address obtaining unit 611 is configured to obtain an address of the resource file, where the resource file is stored in the second terminal, so that the first terminal acquires the resource file according to the address of the resource file.
  • a first terminal as shown in FIG. 9, includes:
  • the query unit 901 is configured to query, by the server, whether the address of the first terminal in the first terminal list is an empty state, and the first terminal list records an address of the first terminal.
  • the resource file obtaining unit 902 is configured to: when the address of the first terminal is in an empty state, the first terminal acquires a resource file from the second terminal.
  • the second canceling unit 903 is configured to notify the server to cancel the clearing state of the address of the first terminal in the first terminal list after acquiring the resource file.
  • the first terminal further includes:
  • a read lock creating unit 904 configured to: when the first terminal acquires resources from the second terminal Before the file, a read lock is created and sent to the server, so that the server sequentially numbers the locks in the order of creation and stores them in the lock directory.
  • the resource file obtaining unit 902 further includes: a resource file obtaining subunit 902 1 configured to acquire a resource file from the second terminal according to the notification of the server; the notification is determined by the server not to exist When the first terminal sends a write lock number with a smaller read lock number, it is sent to the first terminal.
  • the first terminal further includes:
  • the lock deletion notification unit 905 is configured to notify the server that the resource file is obtained after the resource file is obtained from the second terminal, so that the server, after the first terminal completes the resource file acquisition, is in the A read lock corresponding to the first terminal is deleted in the lock directory.
  • a second terminal as shown in FIG. 12, includes:
  • the resource update notification unit 12 1 is configured to send a completed resource update notification message to the server after the update of the resource file is completed, so that the server clears the address of the first terminal in the first terminal list.
  • the second terminal further includes:
  • the write lock creation unit 122 is configured to create a write lock and send the lock to the server before the second terminal performs the update of the resource file, so that the server sequentially numbers the locks according to the creation order, and stores them in the lock directory.
  • the resource file update unit 12 3 is configured to perform update of the resource file according to the notification of the server; the notification is determined by the server that there is no write lock number smaller than a write lock number sent by the second terminal or When the lock number is read, it is sent to the second terminal.
  • the server provided by the embodiment of the present invention, the first terminal and the second terminal, the second terminal notifying the server after the resource file is updated, and the server sets the clear state of the address of the first terminal in the first terminal list to indicate The second terminal has updated the resource file.
  • the first terminal detects that the address in the first list is in the empty state
  • the first terminal may obtain the resource file from the second terminal, and after obtaining the resource file, notify the server to set the first The address of a terminal is cleared.
  • the second terminal does not need to insert a resource record into the database to notify the first terminal resource that the update has been completed, and also prevents the server from adjusting the running program according to the inserted resource record, thereby improving the scalability of the system. And improve the stability of the system operation.
  • the second terminal creates a write lock before updating the resource file, and the first terminal pairs Before the source file is acquired, the read lock is created.
  • the server sequentially numbers the locks by the lock creation time and stores the locks in the lock directory.
  • the server determines whether there is a lock smaller than the write lock number sent by the second terminal or whether there is a write lock smaller than the read lock number sent by the first terminal, to inform the second terminal whether the resource can be used.
  • the file is updated or the first terminal can obtain the resource file.
  • the resource file is written, the other terminal is prohibited from reading or writing to the same resource file.
  • the second terminal is prohibited from writing to the unified resource file, thereby The read/write conflict that occurs when the second terminal updates the resource file and the first terminal acquires the resource file is avoided.
  • the embodiment of the present invention further provides a system for synchronously controlling resources.
  • the system includes: a server 141, a first terminal 142, and a second terminal 143.
  • the second terminal 14 3 notifies the server 141 after the resource file is updated, and the server 141 sets an empty state for the first terminal 142 in the list of the first terminal 142 to indicate the The second terminal 143 has completed the update of the resource file.
  • the first terminal 142 detects that the address of the first terminal 142 is in the empty state, the first terminal 142 can obtain the resource file from the second terminal 14 3, and after acquiring the resource file, The notification server 141 cancels the emptying of the address of the first terminal 142.
  • the second terminal 14 is not required to insert a resource record into the database to inform the first terminal 142 that the resource has been updated, and the server 141 is also prevented from adjusting the running program according to the inserted resource record, thereby improving the system. Scalability and improved system operation stability.
  • the second terminal 143 creates a write lock before updating the resource file
  • the first terminal 142 creates a read lock before acquiring the resource file
  • the server 141 numbers the locks in the order of the lock creation time and stores the lock in the lock directory.
  • the server 141 determines whether there is a lock smaller than the write lock number sent by the second terminal 14 3 or Whether there is a write lock smaller than the read lock number sent by the first terminal 142, to inform the second terminal 14 3 whether the resource file can be updated or whether the first terminal 142 can acquire the resource file.
  • the resource file is written, the other terminal is prohibited from reading or writing to the same resource file.
  • the second terminal is prohibited from writing to the same resource file, thereby The read/write conflict that occurs when the second terminal updates the resource file and the first terminal acquires the resource file is avoided.
  • the present invention has been described by taking the empty state of the address of the terminal as an example.
  • the object of the present invention can also be achieved by setting a flag, an identifier, or the like to explain whether the first terminal has acquired the resource file.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本发明公开了一种对资源进行同步控制的方法、设备和系统,涉及信息同步控制领域,无需第二终端往数据库插入资源记录来告知第一终端资源已经更新完成,同时也避免服务器根据插入的资源记录对正在运行的程序进行调整。一种对资源进行同步控制的方法包括:第一终端向服务器查询第一终端列表中第一终端的地址是否为清空状态;第一终端列表记录有第一终端的地址;当第一终端的地址为清空状态时,第一终端向第二终端获取资源文件;在获取资源文件后,第一终端通知服务器在第一终端列表中取消第一终端的地址的清空状态。本发明用于信息同步控制系统。

Description

一种对资源进行同步控制的方法、 设备和系统 技术领域
本发明涉及信息同步控制领域, 尤其涉及一种对资源进行同步控 制的方法、 设备和系统。
背景技术
现有技术中, 提供的信息同步控制方案是生产者将资源准备完成后, 将 资源文件发送至文件系统或者往数据库插入资源记录; 消费者通过检测文件 系统中的资源文件或者检测数据库中的资源记录来确认生产者是否已将资源 准备完成, 进而向生产者获取资源。
在实现上述技术方案的过程中, 发明人发现现有技术中至少存在 如下问题:
一方面, 生产者往数据库插入资源记录时, 数据库要建立对应于 插入的资源记录的表格, 而且服务器还要根据插入的资源记录对正在 运行的程序进行调整, 这样增加了设备的工作量。 另一方面, 消费者 获取资源是不定时的, 任意时刻消费者都可以进行资源的获取, 如果 消费者在获取资源的同时生产者也在更新资源, 这样就会产生读写冲 突, 影响系统的稳定性。
发明内容
本发明的实施例提供一种对资源进行同步控制的方法、 设备和系 统, 解决了生产者更新资源文件与消费者获取资源文件的读写冲突。
为达到上述目的, 本发明的实施例采用如下技术方案:
一种对资源进行同步控制的方法, 涉及服务器一侧, 包括: 服务器获取第一终端的地址;
所述服务器建立第一终端列表, 所述第一终端列表记录有所述第 一终端的地址;
所述服务器接收所述第二终端发送的已完成资源更新通知消息, 所述已完成资源更新通知消息由所述第二终端完成资源文件的更新后 发送;
在所述服务器接收到所述第二终端发送的已完成资源更新通知消 息后, 为所述第一终端列表中的所述第一终端设置清空状态, 以便于 所述第一终端在所述第一终端列表的所述第一终端为清空状态时, 向 所述第二终端获取资源文件;
在所述第一终端获取资源文件后, 所述服务器根据所述第一终端 的通知, 在所述第一终端列表中取消所述第一终端的清空状态。
一种对资源进行同步控制的方法, 涉及第一终端一侧, 包括: 第一终端向服务器查询第一终端列表中所述第一终端是否为清空 状态, 所述第一终端列表记录有所述第一终端的地址;
当所述第一终端为清空状态时, 所述第一终端向所述第二终端获 取资源文件;
在获取资源文件后, 所述第一终端通知所述服务器在所述第一终 端列表中取消所述第一终端的清空状态。
一种对资源进行同步控制的方法, 涉及第二终端一侧, 包括: 第二终端在完成资源文件的更新后, 向服务器发送已完成资源更 新通知消息, 以便所述服务器为第一终端列表中的第一终端设置清空 状态。
一种服务器, 包括:
地址获取单元, 用于获取第一终端的地址;
列表建立单元, 用于建立第一终端列表, 所述第一终端列表记录 有所述第一终端的地址;
接收单元, 用于接收所述第二终端发送的已完成资源更新通知消 息;所述已完成资源更新通知消息由所述第二终端完成资源文件的更 新后发送;
设置单元, 用于在接收到所述第二终端发送的已完成资源更新通 知消息后, 为所述第一终端列表中的所述第一终端设置清空状态, 以 便于所述第一终端在所述第一终端列表的所述第一终端为清空状态 时, 向所述第二终端获取资源文件;
第一取消单元, 用于在所述第一终端获取资源文件后, 根据所述 第一终端的通知, 在所述第一终端列表中取消所述第一终端的清空状 态。
一种第一终端, 包括:
查询单元, 用于向服务器查询第一终端列表中所述第一终端是否 为清空状态, 所述第一终端列表记录有所述第一终端的地址;
资源文件获取单元, 用于当所述第一终端为清空状态时, 所述第 一终端向所述第二终端获取资源文件;
第二取消单元, 用于在获取资源文件后, 通知所述服务器在所述 第一终端列表中取消所述第一终端的清空状态。
一种笫二终端, 包括:
资源更新通知单元, 用于在完成资源文件的更新后, 向服务器发 送已完成资源更新通知消息, 以便所述服务器为第一终端列表中的第 一终端设置清空状态。
一种对资源进行同步控制的系统, 包括: 上述任意一项所述的服 务器, 第一终端, 以及第二终端。
本发明实施例提供的一种对资源进行同步控制的方法、 设备和系 统, 第二终端在资源文件更新完成后通知所述服务器, 由所述服务器 为第一终端列表中的所述第一终端设置清空状态来表示所述第二终端 已将资源文件更新完成, 无需第二终端往数据库插入资源记录来告知 所述第一终端资源已经更新完成, 同时也避免服务器根据插入的资源 记录对正在运行的程序进行调整。
附图说明
图 1 为本发明实施例 1提供的一种对资源进行同步控制的方法涉 服务器一侧的流程图;
图 2为本发明实施例 1提供的一种对资源进行同步控制的方法涉 第一终端一侧的流程图;
图 3为本发明实施例 2提供的一种对资源进行同步控制的方法的 流程图;
图 4 为本发明实施例 2提供的一种对资源进行同步控制的方法第 二终端进行资源文件更新的流程图;
图 5 为本发明实施例 2提供的一种对资源进行同步控制的方法第 一终端获取资源文件的流程图;
图 6为本发明实施例 3提供的一种服务器框图;
图 7为本发明实施例 3提供的另一种服务器框图;
图 8为本发明实施例 3提供的另一种服务器框图;
图 9为本发明实施例 3提供的一种第一终端框图;
图 1 0为本发明实施例 3提供的另一种第一终端框图; 图 1 1为本发明实施例 3提供的另一种第一终端框图; 图 12为本发明实施例 3提供的另一种第二终端框图;
图 1 3 为本发明实施例 3提供的另一种第二终端框图;
图 1 4为本发明实施例 3提供的一种对资源进行同步控制的系统的 示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行 清楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而 不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做 出创造性劳动前提下所获得的所有其他实施例, 都属于本发明保护的 范围。
本发明实施例的应用场景中, 包括服务器, 第一终端和第二终端 三类设备, 在本发明实施例的应用场景中第一终端可以具体为消费者 所操作的终端, 第二终端可以为生产者所操作的终端。 第二终端中存 储有资源文件, 第一终端需要获取第二终端中的资源文件。 服务器同 时连接第二终端和第一终端。
实施例 1 :
本发明实施例提供了一种对资源进行同步控制的方法, 涉及服务 器一侧, 如图 1所示, 该方法包括:
1 01、 获取第一终端的地址。
第一终端获取资源文件之前, 服务器获取第一终端的地址。
1 02、 建立第一终端列表。
第一终端获取资源文件之前, 服务器建立第一终端列表, 在第一 终端列表中记录有第一终端的地址。
1 03、 接收所述第二终端发送的已完成资源更新通知消息。
当所述第二终端将资源文件更新完后, 会向所述服务器发送已完 成资源更新通知消息。
1 04、 为第一终端列表中的第一终端的地址设置清空状态。
在所述服务器接收到所述第二终端发送的已完成资源更新通知消 息后, 为第一终端列表中的第一终端的地址设置清空状态, 以便于所 述第一终端在所述第一终端列表中的第一终端的地址为清空状态时, 向所述第二终端获取资源文件。
需要说明的是, 为第一终端列表中的第一终端的地址设置清空状 态, 具体的可以是通过将第一终端列表中的第一终端的地址进行删除, 以便于所述第一终端在第一终端列表中的第一终端的地址被删除时, 向所述第二终端获取资源文件。
1 05、 取消第一终端列表中所述第一终端的地址的清空状态。
当第一终端获取资源文件后, 会通知所述服务器已完成資源文件 的获取, 当所述服务器接收到通知后取消第一终端列表中所述第一终 端的地址的清空状态。
需要说明的是, 取消第一终端列表中所述第一终端的地址的清空 状态, 具体的可以是将第一终端的地址重新添加到第一终端列表中。
举例来说明上述步驟 1 01至 1 05。 在系统的初始状态, 服务器分别 获取各个第一终端的地址 , 并将获取的第一终端的地址存入第一终端 列表。 之后, 当第二终端完成资源更新时, 将会向服务器发送已完成 资源更新消息。 服务器接收到已完成资源更新通知消息后, 会为第一 终端列表中第一终端的地址设置清空状态。 当第一终端发现服务器的 第一终端列表中第一终端的地址为清空状态时, 第一终端获知资源文 件已经更新完成, 此时第一终端可以访问第二终端以获取资源文件。 一旦第一终端完成对资源文件的获取后, 会通知服务器。 服务器将取 消第一终端的地址的清空状态。
通过上述步骤, 第二终端将资源文件更新完成通知给所述服务器, 由所述服务器为第一终端的地址设置清空状态来表示所述第二终端已 将资源文件更新完成, 无需第二终端往数据库插入资源记录来告知所 述第一终端资源已经更新完成, 同时也避免服务器根据插入的资源记 录对正在运行的程序进行调整。
本发明实施例还提供了一种对资源进行同步控制的方法, 涉及第 一终端一侧, 如图 2所示, 该方法包括:
2 01、 查询第一终端列表中第一终端的地址是否为清空状态。
所述第一终端在获取资源文件之前, 先要查询第一列表中第一终 端的地址是否为清空状态, 通过查看第一列表中所述第一终端的地址 是否为清空状态来判断所要获取的资源文件是否更新完成, 进而对资 源文件进行获取。 当第一终端列表中第一终端的地址为清空状态时, 执行步骤 202, 否则不进行资源文件的获取动作。
202、 从所述第二终端获取资源文件。
所述第一终端列表中第一终端的地址为清空状态, 说明所述第二 终端已经将资源文件更新完成, 第一终端可以从所述第二终端获取资 源文件。
203、 通知所述服务器在第一终端列表中取消所述第一终端的地址 的清空状态。
当所述第一终端获取资源文件后, 所述第一终端通知所述服务器 在所述第一终端列表中取消所述第一终端的地址的清空状态, 来表示 所述第一终端已将资源文件获取。
另一方面, 在第二终端一侧, 第二终端在完成资源文件的更新后, 向服务器发送已完成资源更新通知消息, 以便所述服务器为第一终端 列表中所述第一终端的地址设置清空状态。
本发明实施例提供了一种对资源进行同步控制的方法, 该方法还 包括:
第一终端获取资源文件之前, 服务器获取第一终端的地址, 第二 终端的地址以及资源文件在第二终端的地址, 当地址获取后, 由服务 器建立第一终端列表, 并将所述第一终端地址存储到第一列表中, 当 通知消息, 所述服务器接收到所述第二终端发送的已完成资源更新通 知消息后, 将第一终端列表中所述第一终端的地址设置为清空状态。 所述第一终端查询所述第一终端列表, 当所述第一终端列表中所述第 一终端的地址为清空状态时, 所述服务器通过所述第二终端获取所述 资源文件的地址, 所述第一终端通过所述资源文件的地址从所述第二 终端获取资源文件。 所述第一终端获取资源文件后, 所述服务器根据 所述第一终端的通知, 取消所述第一终端列表中所述第一终端的地址 的清空状态。
本发明实施例提供了一种对资源进行同步控制的方法, 第二终端 将资源文件更新完成后通知所述服务器, 由所述服务器为第一终端列 表中所述第一终端的地址设置清空状态, 来表示所述生第二终端已将 资源文件更新完成, 减少了第二终端往数据库插入资源记录来告知所 述第一终端资源已经更新完成时, 数据库要建立对应于插入的资源记 录的表格, 服务器根据插入的资源记录对正在运行的程序进行调整所 增加的工作量。
实施例 2 :
本发明实施例提供了一种对资源进行同步控制的方法, 如图 3 所 示, 该方法包括:
301、 服务器获取第一终端的地址。
同时, 服务器还要从第二终端获取存储在第二终端中的资源文件 的地址。
302、 服务器建立第一终端列表, 所述第一终端列表记录有所述第 一终端的地址。
303、 服务器接收所述第二终端发送的已完成资源更新通知消息。 所述已完成资源更新通知消息由所述第二终端完成资源文件的更 新后发送。
304、 服务器记录所述已完成资源更新通知消息的第二终端的地 址。
通过记录所述已完成资源更新通知消息的第二终端的地址, 便于 所述第一终端通过所述服务器记录的第二终端的地址, 找到第二终端 进而获取资源文件。
305、 在所述服务器接收到所述第二终端发送的已完成资源更新通 知消息后, 为第一终端列表中的第一终端的地址设置清空状态。
所述第一终端在检测到所述第一终端列表中第一终端的地址为清 空状态时, 将向所述第二终端获取资源文件。
需要说明的是, 为第一终端列表中的第一终端的地址设置清空状 态, 具体的可以是通过将第一终端列表中的第一终端的地址进行删除, 以便于所述第一终端在第一终端列表中的第一终端的地址被删除时, 向所述第二终端获取资源文件。
306、 第一终端在自身的地址为清空状态时, 向所述第二终端获取 资源文件。
其中, 在第一终端向第二终端获取资源文件前, 可以从服务器中 得到第二终端的地址和资源文件的地址。
307、 在获取资源文件后, 所述第一终端通知所述服务器取消第一 终端的地址的清空状态。 需要说明的是, 取消第一终端列表中所述第一终端的地址的清空 状态, 具体的可以是将第一终端的地址重新添加到第一终端列表中。
举例说明上述步骤 301至 307。 在系统的初始状态下, 服务器首先 获取了全部第一终端的地址, 并存储到第一终端列表中。 同时, 服务 器还从第二终端中得到了资源文件的地址。 之后, 一方面, 第二终端 会进行资源文件的更新, 另一方面, 第一终端会从第二终端获取资源 文件。 假设第二终端 A进行了一次资源文件的更新, A将发送已完成资 源更新通知消息给服务器, 服务器记录 A 的地址并为第一终端列表的 第一终端的地址设置清空状态。 此后, 当有第一终端 (这里假设为第 一终端 B )希望读取 A中的资源文件时, 首先查看在服务器的第一终端 列表中自己的地址是否为清空状态。 由于第一终端列表中 B 的地址为 清空状态, 这时 B从服务器中得到 A的地址以及资源文件的地址, 从 而可以向 A获取资源文件。在获取了资源文件后, B向服务器发送通知, 以便使服务器取消 B的地址的清空状态。 在 B的地址再次设置为清空 状态前, B如果准备再次读取 A中的资源文件, 如果 B的地址在第一终 端列表中不是为清空状态, 表明 A没有对资源文件再次更新, B将中止 资源文件的获取动作。
可见在上述步骤中, 第二终端将资源文件更新完成通知给所述服 务器, 由所述服务器设置所述第一终端的地址为清空状态, 表示所述 第二终端已将资源文件更新完成, 第一终端在检测到第一终端列表中 自身的地址为清空状态时, 可以向第二终端获取资源文件, 在获取资 源文件后, 再通知服务器取消第一终端的地址的清空状态。 通过上述 流程, 无需第二终端往数据库插入资源记录来告知所述第一终端资源 已经更新完成, 同时也避免服务器根据插入的资源记录对正在运行的 程序进行调整, 提升了系统的可扩展性, 并提高了系统运行的稳定性。
实际应用中 , 在分布式系统中的某个终端对资源文件 "改过程中, 需要禁止其他终端进行读取或写入, 以防读取到过期的文件或重复写 入。 zookeepe r是一个针对大型分布式系统的可靠协调系统, zookeeper 有锁文件特性, 具体的, 用户终端可以利用 zookeepe r 系统创建读锁 和写锁对文件进行锁定, 当用户终端先创建写锁对文件锁定时, 任何 其它用户终端不能对该文件更新和读取, 当有读锁对文件锁定时, 用 户终端可以对该文件读取但不能更新,本发明实施例是基于 zookeeper 服务开发的一套同步控制系统, 利用 zookeepe r 的锁特性在本发明实 施例中具体为:
在第二终端进行资源文件更新前, 需要创建写锁, 根据写锁来进 行资源文件更新的方法, 如图 4所示, 包括以下步骤:
401、 第二终端进行资源文件的更新前创建写锁。
402、服务器按照锁创建的顺序对锁依次编号,并存储在锁 H录中。 在锁目录中存储的锁, 是按照锁创建的顺序从小到大依次标号的。 锁目录中存储的锁, 包括第二终端创建的写锁和第一终端创建的读锁。
403、 服务器判断是否存在比所述第二终端发送的写锁编号更小的 锁。
404、 当所述服务器判断不存在比所述第二终端发送的写锁编号更 小的写锁编号或读锁编号时, 通知所述第二终端进行资源文件的更新。
当存在比所述第二终端发送的写锁编号更小的写锁编号或读锁编 号时, 将中止资源文件的更新动作。
405、 服务器在所述第二终端完成资源文件的更新后, 在所述锁目 录中删除与所述第二终端对应的写锁。
第二终端在完成资源文件的更新后, 通知服务器删除与所述第二 终端对应的写锁, 同时向服务器发送已完成资源更新通知消息, 以便 所述服务器为所述第一终端列表中所述第一终端的地址设置清空状 态。
另一方面, 在第一终端进行资源文件获取前, 需要创建读锁, 根 据读锁来进行资源文件获取的方法, 如图 5所示, 包括以下步骤:
501、 第一终端获取资源文件前创建读锁。
502、服务器按照锁创建的顺序对锁依次编号,并存储在锁目录中。 在锁目录中存储的锁, 是按照锁创建的顺序从小到大依次标号的。 锁目录中存储的锁, 包括第二终端创建的写锁和第一终端创建的读锁。
503、 服务器判断是否存在比所述第一终端发送的读锁编号更小的 写锁。
504、 当所述服务器判断不存在比所述第一终端发送的读锁编号更 小的写锁时, 通知所述第一终端向所述第二终端获取资源文件。
当存在比所述第一终端发送的读锁编号更小的写锁时, 将中止第 一终端对资源文件的获取动作。
505、 服务器在所述第一终端获取资源文件后, 在所述锁目录中删 除与所述第一终端对应的读锁。
第一终端在完成资源文件的获取后, 通知服务器已完成资源文件 的获取, 从而使服务器删除与第一终端对应的读锁; 同时通知服务器 取消第一终端的地址的清空状态。
在上述步骤中, 第二终端对资源文件更新以前先创建写锁, 第一 终端对资源文件获取之前先创建读锁, 服务器通过锁创建的时间按顺 序对锁进行编号并将锁存储在锁目录中, 当所述第二终端要对资源更 新或所述第一终端要获取资源文件时, 服务器判断是否存在比所述第 二终端发送的写锁编号更小的锁或是否存在比所述第一终端发送的读 锁编号更小的写锁, 来告知第二终端能否对资源文件进行更新或第一 终端能否荻取资源文件, 通过以上步骤, 一方面, 在对资源文件进行 写操作时, 禁止其他终端对同一资源文件的读或写, 另一方面, 在对 资源文件进行读操作时, 禁止第二终端对同一资源文件进行写操作, 从而避免了第二终端更新资源文件和第一终端获取资源文件时发生的 读写冲突。
实施例 3 :
本发明实施例提供的一种服务器, 如图 6 所示, 包括:
地址获取单元 601 , 用于获取第一终端的地址。
列表建立单元 602, 用于建立第一终端列表, 所述第一终端列表记 录有所述第一终端的地址。
接收单元 603 ,用于接收所述第二终端发送的已完成资源更新通知 消息;所述已完成资源更新通知消息由所述第二终端完成资源文件的 更新后发送。
设置单元 604,用于接收到所述第二终端发送的已完成资源更新通 知消息后, 为所述第一终端列表中的所述第一终端的地址设置清空状 态, 以便于所述第一终端在所述第一终端列表的所述第一终端的地址 为清空状态时, 向所述笫二终端获取资源文件。
第一取消单元 605, 用于在所述第一终端获取资源文件后, 根据所 述第一终端的通知, 在所述第一终端列表中取消所述第一终端的地址 的清空状态。 进一步的, 所述服务器, 如图 7所示, 还包括:
锁接收单元 606 , 用于接收所述笫二终端创建的写锁, 所述写锁由 所述第二终端进行资源文件的更新前创建, 还用于接收所述第一终端 创建的读锁; 所述读锁由所述第一终端向所述第二终端获取资源文件 前创建。
所述服务器还包括:
编号单元 607, 用于按照创建顺序对锁依次编号, 并存储在锁目录 中。
通知单元 608,用于当不存在比所述第二终端发送的写锁编号更小 的写锁编号或读锁编号时, 通知所述第二终端进行资源文件的更新; 所述通知单元还用于当不存在比所述第一终端发送的读锁编号更小的 写锁编号时, 通知所述第一终端获取资源文件。
删除单元 609, 用于在所述第二终端完成资源文件的更新后, 在所 述锁目录中删除与所述第二终端对应的写锁; 所述删除单元还用于在 所述第一终端完成资源文件获取后, 在所述锁目录中删除与所述第一 终端对应的读锁。
进一步的, 如图 8所示, 所述服务器还包括:
记录单元 610,用于在所述服务器接收到所述第二终端发送的已完 成资源更新通知消息后, 记录所述已完成资源更新通知消息的第二终 端的地址。
资源文件地址获取单元 611, 用于获取所述资源文件的地址; 所述 资源文件存储在所述第二终端中, 以便于所述第一终端根据所述资源 文件的地址获取资源文件。
一种第一终端, 如图 9所示, 包括:
查询单元 901,用于向服务器查询第一终端列表中所述第一终端的 地址是否为清空状态, 所述第一终端列表记录有所述第一终端的地址。
资源文件获取单元 902, 用于当所述第一终端的地址为清空状态 时, 所述第一终端向所述第二终端获取资源文件。
第二取消单元 903, 用于在获取资源文件后, 通知所述服务器在所 述第一终端列表中取消所述第一终端的地址的清空状态。
进一步的, 如图 10所示, 所述第一终端还包括:
读锁创建单元 904,用于当所述第一终端向所述第二终端获取资源 文件前, 创建读锁并发送至所述服务器, 以便所述服务器按照创建顺 序对锁依次编号, 并存储在锁目录中。
所述资源文件获取单元 902还包括, 资源文件获取子单元 902 1 , 用于根据所述服务器的通知, 向所述第二终端获取资源文件; 所述通 知由所述服务器判断不存在比所述第一终端发送的读锁编号更小的写 锁编号时, 发送给所述第一终端。
进一步的, 如图 1 1所示, 所述第一终端还包括:
锁删除通知单元 905 , 用于在向所述第二终端获取资源文件后, 通 知所述服务器已完成资源文件的获取, 以便所述服务器在所述第一终 端完成资源文件获取后, 在所述锁目录中删除与所述第一终端对应的 读锁。
一种第二终端, 如图 1 2所示, 包括:
资源更新通知单元 12 1 , 用于在完成资源文件的更新后, 向服务器 发送已完成资源更新通知消息, 以便所述服务器清空第一终端列表中 的所述第一终端的地址。
进一步的, 如图 1 3所示, 所述第二终端还包括:
写锁创建单元 122 , 用于当所述第二终端进行资源文件的更新前, 创建写锁并发送至所述服务器, 以便所述服务器按照创建顺序对锁依 次编号, 并存储在锁目录中。
资源文件更新单元 12 3 , 用于根据所述服务器的通知, 进行资源文 件的更新; 所述通知由所述服务器判断不存在比所述第二终端发送的 写锁编号更小的写锁编号或读锁编号时, 发送给所述第二终端。
本发明实施例提供的服务器, 第一终端和第二终端, 第二终端将 资源文件更新完成后通知所述服务器, 由所述服务器为第一终端列表 中第一终端的地址设置清空状态来表示所述笫二终端已将资源文件更 新完成, 第一终端在检测到第一列表中自身的地址为清空状态时, 可 以向第二终端获取资源文件, 在获取资源文件后, 再通知服务器设置 第一终端的地址为清空状态。 通过上述流程, 无需第二终端往数据库 插入资源记录来告知所述第一终端资源已经更新完成, 同时也避免服 务器根据插入的资源记录对正在运行的程序进行调整, 提升了系统的 可扩展性, 并提高了系统运行的稳定性。
此外, 第二终端对资源文件更新以前先创建写锁, 第一终端对资 源文件获取之前先创建读锁, 服务器通过锁创建的时间按顺序对锁进 行编号并将锁存储在锁目录中, 当所述第二终端要对资源更新或所述 第一终端要获取资源文件时, 服务器判断是否存在比所述第二终端发 送的写锁编号更小的锁或是否存在比所述第一终端发送的读锁编号更 小的写锁, 来告知第二终端能否对资源文件进行更新或第一终端能否 获取资源文件。 一方面, 在对资源文件进行写操作时, 禁止其他终端 对同一资源文件的读或写, 另一方面, 在对资源文件进行读操作时, 禁止第二终端对统一资源文件进行写操作, 从而避免了第二终端更新 资源文件和第一终端获取资源文件时发生的读写冲突。
本发明实施例还提供了一种对资源进行同步控制的系统, 如图 14 所示, 该系统包括: 服务器 141, 第一终端 142, 以及第二终端 14 3。
本发明实施例提供的系统中, 第二终端 14 3 将资源文件更新完成 后通知所述服务器 141, 由所述服务器 141为第一终端 142列表中的第 一终端 142设置清空状态来表示所述第二终端 143 已将资源文件更新 完成, 第一终端 142在检测到第一终端 142列表中自身的地址为清空 状态时, 可以向第二终端 14 3 获取资源文件, 在获取资源文件后, 再 通知服务器 141将第一终端 142的地址取消清空状态。 通过上述流程, 无需第二终端 14 3往数据库插入资源记录来告知所述第一终端 142 资 源已经更新完成, 同时也避免服务器 141 根据插入的资源记录对正在 运行的程序进行调整, 提升了系统的可扩展性, 并提高了系统运行的 稳定性。
此外, 第二终端 143 对资源文件更新以前先创建写锁, 第一终端 142对资源文件获取之前先创建读锁,服务器 141通过锁创建的时间按 顺序对锁进行编号并将锁存储在锁目录中, 当所述第二终端 14 3 要对 资源更新或所述第一终端 142要获取资源文件时, 服务器 141判断是 否存在比所述第二终端 14 3 发送的写锁编号更小的锁或是否存在比所 述第一终端 142发送的读锁编号更小的写锁, 来告知第二终端 14 3 能 否对资源文件进行更新或第一终端 142 能否获取资源文件。 一方面, 在对资源文件进行写操作时, 禁止其他终端对同一资源文件的读或写, 另一方面, 在对资源文件进行读操作时, 禁止第二终端对同一资源文 件进行写操作, 从而避免了第二终端更新资源文件和第一终端获取资 源文件时发生的读写冲突。
在前面对多个实施例的具体描述中, 以设置第一终端列表中第一 终端的地址的清空状态为例说明了本发明。 然而, 通过设置标志位、 标志符等其他方式来说明第一终端是否已获取了资源文件也能实现本 发明的目的。
以上所述, 仅为本发明的具体实施方式, 但本发明的保护范围并 不局限于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范 围内, 可轻易想到变化或替换, 都应涵盖在本发明的保护范围之内。 因此, 本发明的保护范围应所述以权利要求的保护范围为准。

Claims

1、 一种对资源进行同步控制的方法, 其特征在于, 包括: 服务器获取第一终端的地址;
所述服务器建立第一终端列表, 所述第一终端列表记录有所述第 一终端的地址;
所述服务器接收所述第二终端发送的已完成资源更新通知消息, 所述已完成资源更新通知消息由所述第二终端完成资源文件的更新后 发送;
在所述服务器接收到所述第二终端发送的已完成资源更新通知消 息后, 为所述第一终端列表中的所述第一终端设置清空状态, 以便于 所述第一终端在所述第一终端列表中为清空状态时, 向所述第二终端 获取资源文件;
在所述第一终端获取资源文件后, 所述服务器根据所述第一终端 的通知, 在所述第一终端列表中取消所述第一终端的清空状态。
2、 根据权利要求 1所述的方法, 其特征在于, 在接收所述第二终 端发送的已完成资源更新通知消息前, 还包括:
所述服务器接收所述第二终端创建的写锁, 所述写锁由所述第二 终端进行资源文件的更新前创建;
在为所述第一终端列表中的所述第一终端设置清空状态后, 还包 括: 接收所述第一终端创建的读锁; 所述读锁由所述第一终端向所述 第二终端获取资源文件前创建。
3、 根据权利要求 2所述的方法, 其特征在于, 在所述服务器接收 所述第二终端创建的写锁或接收所述第一终端创建的读锁后, 还包括: 所述服务器按照创建顺序对锁依次编号, 并存储在锁目录中; 当所述服务器判断不存在比所述第二终端发送的写锁编号更小的 写锁编号或读锁编号时, 通知所述第二终端进行资源文件的更新;
当所述服务器判断不存在比所述第一终端发送的读锁编号更小的 写锁编号时, 通知所述笫一终端获取资源文件;
所述服务器在所述第二终端完成资源文件的更新后, 在所述锁目 录中删除与所述第二终端对应的写锁;
所述服务器在所述第一终端完成资源文件获取后, 在所述锁目录 中删除与所述第一终端对应的读锁。
4、 根据权利要求 1所述的方法, 其特征在于, 在所述服务器接收 到所述第二终端发送的已完成资源更新通知消息后, 还包括: 记录发送所述已完成资源更新通知消息的第二终端的地址, 以便 于所述第一终端通过所述服务器记录的第二终端的地址, 找到第二终 端进而获取资源文件。
5、 根据权利要求 1或 4所述的方法, 其特征在于, 还包括: 所述服务器获取所述资源文件的地址; 所述资源文件存储在所述 第二终端中, 以便于所述第一终端根据所述资源文件的地址获取资源 文件。
6、 一种对资源进行同步控制的方法, 其特征在于, 包括: 第一终端向服务器查询第一终端列表中所述第一终端是否为清空 状态, 所述第一终端列表记录有所述第一终端的地址;
当所述第一终端为清空状态时, 所述第一终端向所述第二终端获 取资源文件;
在获取资源文件后, 所述第一终端通知所述服务器在所述第一终 端列表中取消所述第一终端的清空状态。
7、 根据权利要求 6所述的方法, 其特征在于, 还包括:
当所述第一终端向所述第二终端获取资源文件前, 创建读锁并发 送至所述服务器, 以便所述服务器按照创建顺序对锁依次编号, 并存 储在锁目录中;
所述第一终端向所述第二终端获取资源文件, 包括:
根据所述服务器的通知, 向所述第二终端获取资源文件; 所述通 知由所述服务器判断不存在比所述第一终端发送的读锁编号更小的写 锁编号时, 发送给所述第一终端。
8、 根据权利要求 7所述的方法, 其特征在于, 在向所述第二终端 获取资源文件后, 还包括:
所述第一终端通知所述服务器已完成资源文件的获取, 以便所述 服务器在所述第一终端完成资源文件获取后, 在所述锁目录中删除与 所述第一终端对应的读锁。
9、 一种对资源进行同步控制的方法, 其特征在于, 包括: 第二终端在完成资源文件的更新后, 向服务器发送已完成资源更 新通知消息, 以便所述服务器为第一终端列表中的第一终端设置清空 状态。
1 0、 根据权利要求 9所述的方法, 其特征在于, 还包括: 当所述第二终端进行资源文件的更新前, 创建写锁并发送至所述 服务器, 以便所述服务器按照创建顺序对锁依次编号, 并存储在锁目 录中;
所述第二终端根据所述服务器的通知, 进行资源文件的更新; 所 述通知由所述服务器判断不存在比所述笫二终端发送的写锁编号更小 的写锁编号或读锁编号时, 发送给所述第二终端。
11、 一种服务器, 其特征在于, 包括:
地址获取单元, 用于获取第一终端的地址;
列表建立单元, 用于建立第一终端列表, 所述第一终端列表记录 有所述第一终端的地址;
接收单元, 用于接收所述第二终端发送的已完成资源更新通知消 息;所述已完成资源更新通知消息由所述第二终端完成资源文件的更 新后发送;
设置单元, 用于接收到所述第二终端发送的已完成资源更新通知 消息后, 为所述第一终端列表中的所述第一终端设置清空状态, 以便 于所述第一终端在所述第一终端列表的所述第一终端为清空状态时, 向所述第二终端获取资源文件;
第一取消单元, 用于在所述第一终端获取资源文件后, 根据所述 第一终端的通知, 在所述第一终端列表中取消所述第一终端的清空状 太
12、 根据权利要求 11所述的服务器, 其特征在于, 所述服务器还 包括:
锁接收单元, 用于接收所述第二终端创建的写锁, 所述写锁由所 述第二终端进行资源文件的更新前创建;
还用于接收所述第一终端创建的读锁; 所述读锁由所述第一终端 向所述第二终端获取资源文件前创建。
13、 根据权利要求 12所述的服务器, 其特征在于, 所述服务器还 包括:
编号单元, 用于按照创建顺序对锁依次编号, 并存储在锁目录中; 通知单元, 用于当不存在比所述第二终端发送的写锁编号更小的 写锁编号或读锁编号时, 通知所述第二终端进行资源文件的更新; 所 述通知单元还用于当不存在比所述第一终端发送的读锁编号更小的写 锁编号时, 通知所述第一终端获取资源文件;
删除单元, 用于在所述第二终端完成资源文件的更新后, 在所述 锁目录中删除与所述第二终端对应的写锁; 所述删除单元还用于在所 述第一终端完成资源文件获取后, 在所述锁目录中删除与所述第一终 端对应的读锁。
1 4、 根据权利要求 1 1所述的服务器, 其特征在于, 所述服务器还 包括:
记录单元, 用于在接收到所述第二终端发送的已完成资源更新通 知消息后, 记录所述已完成资源更新通知消息的第二终端的地址。
1 5、 根据权利要求 1 1 或 14所述的服务器, 其特征在于, 所述服 务器还包括:
资源文件地址获取单元, 用于获取所述资源文件的地址; 所述资 源文件存储在所述第二终端中, 以便于所述第一终端根据所述资源文 件的地址获取资源文件。
1 6、 一种第一终端, 其特征在于, 包括:
查询单元, 用于向服务器查询第一终端列表中所述第一终端是否 为清空状态, 所述第一终端列表记录有所述第一终端的地址;
资源文件获取单元, 用于当所述第一终端为清空状态时, 所述第 一终端向所述第二终端获取资源文件;
第二取消单元, 用于在获取资源文件后, 通知所述服务器在所述 第一终端列表中取消所述第一终端的清空状态。
1 7、 根据权利要求 1 6所述的第一终端, 其特征在于, 还包括: 读锁创建单元, 用于在所述第一终端向所述第二终端获取资源文 件前, 创建读锁并发送至所述服务器, 以便所述服务器按照创建顺序 对锁依次编号, 并存储在锁目录中;
所述资源文件获取单元, 包括:
资源文件获取子单元, 用于根据所述服务器的通知, 向所述第二 终端获取资源文件; 所述通知由所述服务器判断不存在比所述第一终 端发送的读锁编号更小的写锁编号时, 发送给所述笫一终端。
1 8、 居权利要求 1 7所述的第一终端, 其特征在于, 还包括: 锁删除通知单元, 用于在向所述第二终端获取资源文件后, 通知 所述服务器已完成资源文件的获取, 以便所述服务器在所述第一终端 完成资源文件获取后, 在所述锁目录中删除与所述第一终端对应的读 锁。
1 9、 一种第二终端, 其特征在于, 包括: 资源更新通知单元, 用于在完成资源文件的更新后, 向服务器发 送已完成资源更新通知消息, 以便所述服务器为所述第一终端列表中 的所述第一终端设置清空状态。
20、 根据权利要求 1 9所述的第二终端, 其特征在于, 还包括: 写锁创建单元, 用于在所述第二终端进行资源文件的更新前, 创 建写锁并发送至所述服务器, 以便所述服务器按照创建顺序对锁依次 编号, 并存储在锁目录中;
资源文件更新单元, 用于根据所述服务器的通知, 进行资源文件 的更新; 所述通知由所述服务器判断不存在比所述第二终端发送的写 锁编号更小的写锁编号或读锁编号时, 发送给所述第二终端。
2 1、 一种对资源进行同步控制的系统, 其特征在于, 所述系统包 括如权利要求 1 1至 1 5中任意一项所述的服务器,如权利要求 1 6至 18 中任意一项所述的第一终端, 以及如权利要求 19 至 20 中任意一项所 述的第二终端。
PCT/CN2013/081296 2012-09-29 2013-08-12 一种对资源进行同步控制的方法、设备和系统 WO2014048176A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US14/431,643 US9380109B2 (en) 2012-09-29 2013-08-12 Resource synchronization control method, device, and system

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210376133.X 2012-09-29
CN201210376133.XA CN103716350B (zh) 2012-09-29 2012-09-29 一种对资源进行同步控制的方法、设备和系统

Publications (1)

Publication Number Publication Date
WO2014048176A1 true WO2014048176A1 (zh) 2014-04-03

Family

ID=50386950

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/081296 WO2014048176A1 (zh) 2012-09-29 2013-08-12 一种对资源进行同步控制的方法、设备和系统

Country Status (3)

Country Link
US (1) US9380109B2 (zh)
CN (1) CN103716350B (zh)
WO (1) WO2014048176A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107562648B (zh) * 2016-07-01 2021-04-06 北京忆恒创源科技有限公司 无锁ftl访问方法与装置
CN114242211A (zh) * 2021-12-20 2022-03-25 王兆河 保障云pacs系统影像数据传输完整性的方法及装置
CN116405146B (zh) * 2023-04-04 2024-01-30 惠州市德赛智储科技有限公司 多bms从机同步控制方法及控制系统

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101795203A (zh) * 2009-02-03 2010-08-04 华为软件技术有限公司 软件升级数据包的下载方法和装置
KR20120002344A (ko) * 2010-06-30 2012-01-05 (주)나무소프트 파일 동기화 방법 및 장치
CN102624569A (zh) * 2012-04-18 2012-08-01 华为技术有限公司 对终端进行升级的方法和系统、网络设备以及终端

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7315926B2 (en) * 2004-09-21 2008-01-01 Emc Corporation Lock management for concurrent access to a single file from multiple data mover computers
WO2007102536A1 (ja) * 2006-03-08 2007-09-13 Matsushita Electric Industrial Co., Ltd. 分散ファイル管理システム
CN101488924B (zh) * 2009-02-16 2011-11-16 成都市华为赛门铁克科技有限公司 一种元数据的修改方法和元数据服务器

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101795203A (zh) * 2009-02-03 2010-08-04 华为软件技术有限公司 软件升级数据包的下载方法和装置
KR20120002344A (ko) * 2010-06-30 2012-01-05 (주)나무소프트 파일 동기화 방법 및 장치
CN102624569A (zh) * 2012-04-18 2012-08-01 华为技术有限公司 对终端进行升级的方法和系统、网络设备以及终端

Also Published As

Publication number Publication date
US9380109B2 (en) 2016-06-28
CN103716350A (zh) 2014-04-09
US20150256614A1 (en) 2015-09-10
CN103716350B (zh) 2018-03-30

Similar Documents

Publication Publication Date Title
US20190026190A1 (en) Restoring data in a hierarchical storage management system
US9952783B2 (en) Data processing method and apparatus, and shared storage device
JP4732661B2 (ja) クライアントのデータベースとサーバーのデータベースとを同期させる方法
US10817498B2 (en) Distributed transactions in cloud storage with hierarchical namespace
JP6564026B2 (ja) マルチテナントアプリケーションサーバ環境におけるトランザクション回復のためのシステムおよび方法
US20190370362A1 (en) Multi-protocol cloud storage for big data and analytics
US20190370360A1 (en) Cloud storage distributed file system
US10289692B2 (en) Preserving file metadata during atomic save operations
US7953710B2 (en) Multi-master database synchronization without loss of convergence
JP6220850B2 (ja) データベースへの中間層トランザクションログのインライン委譲をサポートするためのシステムおよび方法
EP3189446A1 (en) A method, cloud synchronization function means and file system for handling files and directories in a cloud storage service
JP6475304B2 (ja) トランザクション処理方法および装置
JP2005222552A5 (zh)
US9460103B2 (en) File synchronization method, files synchronization apparatus and electronic device
JP6196389B2 (ja) 分散型ディザスタリカバリファイル同期サーバシステム
JP6940645B2 (ja) レプリカ処理方法、ノード、ストレージシステム、サーバ及び読み取り可能な記憶媒体
WO2014048176A1 (zh) 一种对资源进行同步控制的方法、设备和系统
US9990378B2 (en) Opportunistic clearing of sync states associated with a database
JP2009251756A (ja) クライアント装置、分散ファイルシステム、共有リソース多重化方法およびプログラム
CN106354830B (zh) 一种数据库集群节点间数据同步的方法及装置
US20120150924A1 (en) Apparatus for supporting continuous read/write in asymmetric storage system and method thereof
EP1934783A1 (en) Productivity suite to line of business synchronization mechanism
CN108255848B (zh) 实现条件更新的方法、设备及系统
JP6158361B2 (ja) 情報処理装置及び方法
JP6336323B2 (ja) 情報処理装置、制御方法およびプログラム

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13841118

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 14431643

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 18/08/2015)

122 Ep: pct application non-entry in european phase

Ref document number: 13841118

Country of ref document: EP

Kind code of ref document: A1