CN102681892B - Key-Value type write-once read-many lock pool software module and running method thereof - Google Patents

Key-Value type write-once read-many lock pool software module and running method thereof Download PDF

Info

Publication number
CN102681892B
CN102681892B CN201210150721.1A CN201210150721A CN102681892B CN 102681892 B CN102681892 B CN 102681892B CN 201210150721 A CN201210150721 A CN 201210150721A CN 102681892 B CN102681892 B CN 102681892B
Authority
CN
China
Prior art keywords
lock
worm
logic
key
read
Prior art date
Legal status (The legal status 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 status listed.)
Expired - Fee Related
Application number
CN201210150721.1A
Other languages
Chinese (zh)
Other versions
CN102681892A (en
Inventor
肖舸
葛新
李伟伟
杨东
王毅
王文庆
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian TPRI Power Station Information Technology Co Ltd
Original Assignee
Thermal Power Research Institute
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 Thermal Power Research Institute filed Critical Thermal Power Research Institute
Priority to CN201210150721.1A priority Critical patent/CN102681892B/en
Publication of CN102681892A publication Critical patent/CN102681892A/en
Application granted granted Critical
Publication of CN102681892B publication Critical patent/CN102681892B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a Key-Value type write-once read-many lock pool software module and a running method thereof. The module comprises an application program calling interface, a write-once read-many operation logical layer, a Hash managing module, a dynamic memory pool module and a system physical lock resource which are coupled with one another and work in a linked way; and a plenty of write-once read-many logical locks are provided for developing other application programs. The running method comprises the following steps of: calling an application program calling interface by taking any data as a Key through an application program; making a lock access request including adding write lock, unlocking write lock, adding read lock, unlocking read lock and inquiring a load read-write state; connecting the application program calling interface to the access request; and transferring to a write-once read-many operation logical layer to realize service. According to the module and the method, a large quantity of write-once read-many lock resources can be provided for an application layer to use by using a small quantity of operating system resources, an efficient ''small lock'' application model is realized, and the high-performance development requirement in a multi-task environment in the software industry is met.

Description

Key-Value type WORM lock pond software module and operation method thereof
Technical field
The present invention relates to parallel computation field Zhong Suo pond software module and method, be specifically related to a kind of Key-Value type WORM lock pond software module and operation method thereof.
Background technology
Lock is a kind of valuable source that multiple task operating system provides, common are the various ways such as critical section, semaphore, mutex, its Core Feature is in parallel Programming field, when two or more threads face while accessing some resources (internal memory, Socket, IO etc.) possible simultaneously, this resource of provisional declaration is being taken (Lock) by certain thread sometime, prevent the conflict access of other threads, to ensure that each access action is all intactly completed in the authority of oneself needs, avoids program bug.
At large server development field, owing to will tackling the high speed of a large amount of clients, concurrent greatly, mass data access, the access of the resource such as internal data module configured, communication module and variation very dense, need the lock resource of efficient and magnanimity to support, the integrality of guarantee data access and security, and the efficiency of guarantee resource access.
Traditional latching operation program design mode is generally divided into two kinds:
1, definition one is " lock greatly "; protect a complete data structure; such as all data in a lock protection one tree type data structure, a queue, a storehouse; all the access of this data structure is all needed to realize by this lock; this takies seldom operating-system resources; but can cause large Concurrency Access time, lock collision is too intensive, and access efficiency is very low.
2, definition is much " little lock "; subdata that segment, very among a small circle in protected data structure; such as a lock is only protected a slice " leaf " in tree form data structure; in program, lock is with data resource according to the configuration of 1:1 quantity, and this can reduce lock collision and promote access efficiency.But because lock itself is also the resource of operating system, in the tissue of mass data, system resources consumption can be very large, can cause system to be collapsed because of inadequate resource, or program is forced to arrange the upper limit, cannot protect too many resource.
Above-mentioned two schemes is all imperfect, or performance is low, or serious waste of resources, and the two is difficult to compromise.A kind of high efficiency, low system resource of software industry shortage takies at present, for the lock salvo of mass data.This has seriously restricted performance and the scale of high concurrent mass data application server.
In addition, the lock resource that legacy operating system provides, its locking method comparison " rough ", the two kinds of modes of operation of (Lock) and release (Unlock) that only lock, do not segment the data access behavior that applications is concrete.This causes locking is at every turn all unconditional " exclusive ", cannot be concurrent, and performance is not high.
But in real work; data access has " reading ", " writing " two kinds of demands conventionally; research shows, under " writing " mode, really needs the lock protection of " exclusive "; prevent bug; and under " reading " mode, because protected data resource is not modified, can allow multiple " reading " concurrent; allow multiple threads to read certain resource, to promote the concurrent efficiency of program simultaneously.
This needs WORM lock logic, i.e. the application layer latching operation behavior of " segmentation ", clearly difference " writing action " and " reading to move ", in addition different processing, the lock protective capability of realization " unique writing " and " concurrent reading ".
At present, most of multiple task operating systems do not provide " WORM lock " resource, and also ununified standard of software industry needs programmer to realize voluntarily in development.But because WORM lock logic development difficulty is larger, industry programmer's level is uneven again, in doing in fact, often goes wrong, and has affected program development work efficiency.
Software industry relatively lacks at present comparatively general, have higher abstractness, friendly application development interface API is provided, can be cross-platform, across the WORM lock resource solution of language call.
Summary of the invention
The shortcoming existing in order to overcome above-mentioned prior art, the object of the present invention is to provide a kind of Key-Value type WORM lock pond software module and operation method thereof, can use little operating-system resources (physical locks resource, internal memory etc.), provide magnanimity " WORM logic lock " resource provisioning layer to use, to realize " little lock " application model efficiently, meet the high-performance development requirement under multitask environment of software industry.
In order to achieve the above object, the technical solution adopted in the present invention is:
A kind of Key-Value type WORM lock pond software module, comprises and intercoupling, the following submodule of linkage work:
Application call interface: define the method for operating of this module, call for other computer programming languages, practical function output;
WORM operation logic layer: provide WORM algorithm logic, for each logic lock of realizing provides WORM operating characteristic;
Hash administration module: accept the Key key assignments of arbitrary data types, quick indexing is searched corresponding WORM logic lock, realizes the accurate access of multiple WORM logic locks;
Dynamic memory pool module: realize dynamic application and the release of inner WORM logic lock data;
System physical locks resource: to the lock resource of operating system application, it adds unlock method this modular program run time call, provides the multithreading safeguard protection of this module self function.
Described lock pond software module provides magnanimity WORM logic lock for other application developments, described WORM logic lock comprises two characteristics, write zone bit and a read counter for one, can store, describe the operation state values of " unique writing " and " multiple reading ", its core data belongs to internal storage data, can indexed management in Hash administration module, also can be by the dynamically application and discharging of dynamic memory pool module, its logical definition is as follows:
1) writing flag set is 1, represents that this logic lock, in " writing " state, forbids that other " writing " or " reading " action enters at present, and cannot again arrange and write zone bit is 1, or stack read counter;
2) read counter stack, is not 0, represents to have at present " reading " action, does not allow other " writing " action to enter, and cannot arrange and write zone bit is 1, but other " reading " action can be concurrent, and this value that is embodied in read counter constantly increases.
An operation method for Key-Value type WORM lock pond software module, comprises the steps:
Step 1: application program is using arbitrary data as Key, call this software module application call interface, lock request of access is proposed, described request comprises adding to be write lock, solution and writes lock, read lock, solution read lock and inquiry lock read-write state, application call interface is received request of access, forwards WORM operation logic layer to and realizes service;
Step 2: WORM operation logic layer method of service is as follows:
Move for " add and write lock " or " read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, if there is no, to WORM logic lock of dynamic memory pool module application, then push Hash administration module and carry out index management, now this WORM logic lock is considered as existing; If existed, directly add latching operation, return to operating result;
Move for " solution is write lock " or " solution read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist directly and return, do not do anything, exist and carry out unlocking operation, after release, check whether it also has other locking states, if nothing, from Hash administration module, delete the index of this WORM logic lock, and discharge this WORM logic lock resource to dynamic memory pool module;
For reading lock status action, whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist and directly return to lock unused state, existence is read real data mode in WORM logic lock and is returned;
Above-mentioned everything all completes under system physical locks protection same, is not interrupted when ensureing everything operation, guarantees the multithreading security of this software module self.
Described operation method comprises following application call interface and relevant WORM logical layer program circuit:
Write lock status query interface: the WORM logic lock that inquiry Key specifies write lock status, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read and wherein write mark, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Read lock status poll interface: the read counter state of value of the WORM logic lock that inquiry Key specifies, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read wherein read counter, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Trial adds writes lock interface: write lock for the WORM logic lock of Key appointment adds, if this WORM logic lock is added and reads or write lock, unsuccessfully return to vacation, or after successfully locking, return very, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create WORM logic lock, be set to vacation if create failed rreturn value, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock of just having set up, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added read lock or write lock, if add and lock, rreturn value is set to vacation
If f) can lock, write mark and be set to 1 realization and lock, rreturn value is set to very simultaneously
G) separate this modular system physical locks
H) check rreturn value, false if, represent to lock unsuccessful, function directly returns to vacation, finishes
If i) rreturn value is true, represent to write lock and add successfully, need to arrange unlimited endless loop, constantly call read lock status poll interface, detect whether all read locks are all removed, be 0 until obtain read counter, side jumps out circulation, returns true;
Determine to add and write lock interface: for adding, the WORM logic lock of Key appointment writes lock, if this WORM logic lock is added and is read or write lock, circular wait, until successfully lock, specific procedure flow process is as follows:
A) unlimited endless loop is set, constantly calls and attempt adding writing lock interface
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Lock interface is write in releasing: write lock for the WORM logic lock releasing that Key specifies, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, setting is write and is masked as 0, destroys WORM logic lock, deletes this lock index, releasing resource from Hash administration module simultaneously
E) separate this modular system physical locks, return;
Attempt read lock interface: for the WORM logic lock read lock that Key specifies, if this WORM logic lock is added and writes lock, unsuccessfully return to vacation, or after successfully locking, return very, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create, if create failed rreturn value, vacation is set, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock just having created, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added to write lock, if locked, rreturn value is set to vacation
If f) can lock, read counter+1 is realized and being locked, rreturn value is set to very simultaneously
G) separate this modular system physical locks, return to rreturn value;
Determine read lock interface: for the WORM logic lock read lock of Key appointment, if this WORM logic lock is added and is write lock, circular wait, until successfully add read lock, specific procedure flow process is as follows:
A) unlimited endless loop is set, constantly calls trial read lock
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Remove read lock interface: remove read lock for the WORM logic lock that Key specifies, specific procedure flow process is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, read counter-1, if <=0 of read counter now destroys WORM logic lock, deletes this lock index, releasing resource from Hash administration module simultaneously
E) separate this modular system physical locks, return.
The application call interface of described lock pond software module, for all computer programming language routine calls with call operation system API ability, comprises C, C++, compilation, Java, C#, VB.
Described lock pond software module provides the version of different operating system, realizes spanning operation system platform function, can under Windows, Linux and some other class Unix platform, work, and module product can be organized as following form, practical function output:
.h header file definition (application development interface declaration definition) (Windows, Linux, Unix like)
.dll dynamic link library (Windows)
.so dynamic link library (Linux, Unix like)
.obj Object linking file (Windows, Linux, Unix like)
.lib static link library (Windows, Linux, Unix like)
Compared to the prior art, tool has the following advantages in the present invention:
The common operating system of its function ratio of WORM logic lock of the present invention's definition is locked powerful, be characterized in segmenting the outside action type to data resource, operate for " writing ", realize " unique writing " principle of complete exclusiveness, now be equivalent to the Lock that locks of operating system lock, and for " reading " operation, allow " concurrent reading " conditionally, can improve the concurrent work efficiency of multi-thread software system.
Coordinate again the dynamic memory management principle of C/C++ language, the present invention defines one to be only had WORM logic lock to be just really instantiated as in use effective internal storage data, while use, discharge back Installed System Memory in time, can, with little memory cost, realize the WORM logic lock of magnanimity for application program.
Brief description of the drawings
Fig. 1 is for writing lock status querying flow figure.
Fig. 2 is read lock status poll process flow diagram.
Fig. 3 writes lock process flow diagram for attempting adding.
Fig. 4 writes lock process flow diagram for determining to add.
Fig. 5 writes lock process flow diagram for removing.
Fig. 6 is for attempting read lock process flow diagram.
Fig. 7 is for determining read lock process flow diagram.
Fig. 8 is for removing read lock process flow diagram.
Embodiment
Below in conjunction with embodiment and accompanying drawing, the present invention is described in further detail.
A kind of Key-Value type of the present invention WORM lock pond software module, comprises and intercoupling, the following submodule of linkage work:
Application call interface: define the method for operating of this module, call for other computer programming languages, practical function output;
WORM operation logic layer: provide WORM algorithm logic, for each logic lock of realizing provides WORM operating characteristic;
Hash administration module: accept the Key key assignments of arbitrary data types, quick indexing is searched corresponding WORM logic lock, realizes the accurate access of multiple WORM logic locks;
Dynamic memory pool module: realize dynamic application and the release of inner WORM logic lock data;
System physical locks module: to the lock resource of operating system application, it adds unlock method Calling, provides the multithreading safeguard protection of this module self function.
Described lock pond software module provides magnanimity WORM logic lock for other application developments, described WORM logic lock comprises two characteristics, write zone bit and a read counter for one, can store, describe the operation state values of " unique writing " and " multiple reading ", its core data belongs to internal storage data, can indexed management in Hash administration module, also can be by the dynamically application and discharging of dynamic memory pool module, its logical definition is as follows:
1) writing flag set is 1, represents that this logic lock, in " writing " state, forbids that other " writing " or " reading " action enters at present, and cannot again arrange and write zone bit is 1, or stack read counter;
2) read counter stack, is not 0, represents to have at present " reading " action, does not allow other " writing " action to enter, and cannot arrange and write zone bit is 1, but other " reading " action can be concurrent, and this value that is embodied in read counter constantly increases;
The operation method of Key-Value type WORM lock of the present invention pond software module, comprises the steps:
Step 1: application program is using arbitrary data as Key, call this software module application call interface, lock request of access is proposed, described request comprises adding to be write lock, solution and writes lock, read lock, solution read lock and inquiry lock read-write state, application call interface is received request of access, forwards WORM operation logic layer to and realizes service;
Step 2: WORM operation logic layer method of service is as follows:
Move for " add and write lock " or " read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, if there is no, to WORM logic lock of dynamic memory pool module application, then push Hash administration module and carry out index management, now this WORM logic lock is considered as existing; If existed, directly add latching operation, return to operating result;
Move for " solution is write lock " or " solution read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist directly and return, do not do anything, exist and carry out unlocking operation, after release, check whether it also has other locking states, if nothing, from Hash administration module, delete the index of this WORM logic lock, and discharge this WORM logic lock resource to dynamic memory pool module;
For reading lock status action, whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist and directly return to lock unused state, existence is read real data mode in WORM logic lock and is returned;
Above-mentioned everything all completes under system physical locks protection same, is not interrupted when ensureing everything operation, guarantees the multithreading security of this software module self.
Described operation method comprises following application call interface and relevant WORM logical layer program circuit:
Write lock status query interface: the WORM logic lock that inquiry Key specifies write lock status, specific procedure flow process as shown in Figure 1:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read and wherein write mark, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Read lock status poll interface: the read counter state of value of WORM logic lock that inquiry Key specifies, specific procedure flow process as shown in Figure 2:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read wherein read counter, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Trial adds writes lock interface: the WORM logic lock of specifying for Key adds and writes lock, if this WORM logic lock is added and reads or write lock, unsuccessfully returns to vacation, or after successfully locking, return true, specific procedure flow process as shown in Figure 3:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create WORM logic lock, be set to vacation if create failed rreturn value, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock of just having set up, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added read lock or write lock, if add and lock, rreturn value is set to vacation
If f) can lock, write mark and be set to 1 realization and lock, rreturn value is set to very simultaneously
G) separate this modular system physical locks
H) check rreturn value, false if, represent to lock unsuccessful, function returns to vacation, directly finishes
If i) rreturn value is true, represent to write lock and add successfully, need to arrange unlimited endless loop, constantly call read lock status poll interface, detect whether all read locks are all removed, be 0 until obtain read counter, side jumps out circulation, returns true;
Determine and add and write lock interface: the WORM logic lock of specifying for Key adds writes lock, if this WORM logic lock is added and is read or write lock, circular wait, until successfully lock, specific procedure flow process as shown in Figure 4:
A) unlimited endless loop is set, constantly calls and attempt adding writing lock interface Try2EnableWrite
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Lock interface is write in releasing: the WORM logic lock of specifying for Key is removed and write lock, specific procedure flow process as shown in Figure 5:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, arranging and writing zone bit is 0, destroys WORM logic lock, deletes this lock index, releasing resource from Hash administration module simultaneously
E) separate this modular system physical locks, return;
Attempt read lock interface: for the WORM logic lock read lock that Key specifies, if this WORM logic lock is added and writes lock, unsuccessfully return to vacation, or after successfully locking, return true, specific procedure flow process as shown in Figure 6:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create, if create failed rreturn value, vacation is set, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock just having created, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added to write lock, if locked, rreturn value is set to vacation
If f) can lock, read counter+1 is realized and being locked, rreturn value is set to very simultaneously
G) separate this modular system physical locks, return to rreturn value;
Determine read lock interface: the WORM logic lock read lock of specifying for Key, if this WORM logic lock is added and is write lock, circular wait, until successfully add read lock, specific procedure flow process as shown in Figure 7:
A) unlimited endless loop is set, constantly calls and attempt read lock Try2AddRead
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Remove read lock interface: be that the WORM logic lock that Key specifies is removed read lock, specific procedure flow process as shown in Figure 8:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, read counter-1, if <=0 of read counter now destroys WORM logic lock, deletes this lock index, releasing resource from Hash administration module simultaneously
E) separate this modular system physical locks, return.
The application call interface of described lock pond software module, for all computer programming language routine calls with call operation system API ability, comprises C, C++, compilation, Java, C#, VB.
Described lock pond software module provides the version of different operating system, realizes spanning operation system platform function, can under Windows, Linux and some other class Unix platform, work, and module product can be organized as following form, practical function output:
.h header file definition (application development interface declaration definition) (Windows, Linux, Unix like)
.dll dynamic link library (Windows)
.so dynamic link library (Linux, Unix like)
.obj Object linking file (Windows, Linux, Unix like)
.lib static link library (Windows, Linux, Unix like)
Development procedure of the present invention:
The present invention utilizes the structure of C language, defines a WORM logic lock, preserves WORM logic relevant information.
Utilize the compiling macro definition of C language, the access function of the different lock of abstract different operating system platform resource, provides standard calls method, realizes cross-platform transfer ability.
Exploitation C language function, provides the standard access function that WORM logic is relevant: add solutions and " write " to lock and add solution and " read " to lock, status poll function etc.All functions all can be for above-mentioned WORM logic lock operation.
Exploitation dynamic memory management module, it is memory pool, this step can be omitted, directly use malloc, the free function of C language, or the new of C Plus Plus, delete function are realized, and the present invention adopts the memory pool of inventor's designed, designed, be only used to reclaim and reuse internal memory, avoid memory fragmentation, meet server 7*24 hour long-play demand.This is not right emphasis of the present invention, repeats no more.
Exploitation Hash administration module, this step also can be omitted, and directly uses the Map class of C Plus Plus to realize, and the present invention adopts the Hash pond module of inventor's designed, designed, is in order to keep larger flexibility ratio and high efficiency.This is not right emphasis of the present invention, repeats no more.
Aforementioned WORM logic lock indicator index is defined as to the Value of Hash administration module, making every a slice " leaf " of Hash administration module is all the index of a WORM logic lock.Key does not limit, and application layer can be used arbitrary data as Key, looks for corresponding WORM logic lock in Hash pond, realizes operation.
Arbitrary data can be one section of binary data, a C language structure, a character string, an integer, or other data, by application layer, programmer plans, as long as ensure uniqueness, Key can only corresponding one logic lock, two different Key must the different logic lock of correspondence.
Design one, system physical locks, with above-mentioned logic lock interlock, guarantees that the retrieval in Hash pond, the operation of WORM lock body all complete by this system physical locks, and making all lock pond operations itself is multithreading safety.
Design standards application call interface, the access behavior of specification software module of the present invention, provides the unified interface of calling, for different application layer.
In programming procedure, pay close attention to professional platform independence, do not allow to call the distinctive function of each operating system, the power function that uses standard C/C Plus Plus to provide is only provided, pass through again different compilers, be compiled as the various binary code modules such as obj, lib, dll, so, allow application layer cross-platform, call practical function output across language compiling link.
Application example:
The present invention Rython in real time/historical data base plateform system in, applied Multi-instance.
In an application-specific example, need to do lock protection for data paragraphs different in thousands of data files, with the data resource secure access of guaranteeing height and give therein.Through calculating, the quantity size of lock demand is 400,000,000 locks.Certainly, traditional " little lock " model, under so large scale, will cause serious system resource bottleneck, can not realize, and the performance requirement of system does not allow to use inefficient " lock greatly " model.
Through to application of the present invention, system has obtained and has exceeded the concurrent reading and writing of 150,000 times/second up to the logic lock of 400,000,000 handles for, support simultaneously and access, and the actual system resource taking is little, has realized the demand.

Claims (6)

1. the system that realizes in Key-Value type WORM lock pond, is characterized in that: comprise and intercoupling, the following submodule of linkage work:
Application call interface: define the method for operating of this module, call for other computer programming languages, practical function output;
WORM operation logic layer: provide WORM algorithm logic, for each logic lock of realizing provides WORM operating characteristic;
Hash administration module: accept the Key key assignments of arbitrary data types, quick indexing is searched corresponding WORM logic lock, realizes the accurate access of multiple WORM logic locks;
Dynamic memory pool module: realize dynamic application and the release of inner WORM logic lock data;
System physical locks module: to operating system application lock resource, it adds unlock method Calling, and the multithreading safeguard protection of this module self function is provided.
2. the system that realizes in Key-Value type WORM lock according to claim 1 pond, it is characterized in that: provide magnanimity WORM logic lock for other application developments, described WORM logic lock comprises two characteristics, write zone bit and a read counter for one, can store, describe the operation state values of " unique writing " and " multiple reading ", its core data belongs to internal storage data, can indexed management in Hash administration module, also can be by dynamically application and the release of dynamic memory pool module, its logical definition is as follows:
1) writing flag set is 1, represents that this logic lock, in " writing " state, forbids that other " writing " or " reading " action enters at present, and cannot again arrange and write zone bit is 1, or stack read counter;
2) read counter stack, is not 0, represents to have at present " reading " action, does not allow other " writing " action to enter, and cannot arrange and write zone bit is 1, but other " reading " action can be concurrent, and this value that is embodied in read counter constantly increases.
3. the operation method of the system that realizes in Key-Value type WORM lock pond described in claim 1, is characterized in that: comprise the steps:
Step 1: application program is using arbitrary data as Key, call this software module application call interface, lock request of access is proposed, described request comprise add write lock, solution is write lock, read lock, solution read lock and inquiry and is read lock status, application call interface is received request of access, forwards WORM operation logic layer to and realizes service;
Step 2: WORM operation logic layer method of service is as follows:
Move for " add and write lock " or " read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, if there is no, to WORM logic lock of dynamic memory pool module application, then push Hash administration module and carry out index management, now this WORM logic lock is considered as existing; If existed, directly add latching operation, return to operating result;
Move for " solution is write lock " or " solution read lock ", whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist directly and return, do not do anything, exist and carry out unlocking operation, after release, check whether it also has other locking states, if nothing, from Hash administration module, delete the index of this WORM logic lock, and discharge this WORM logic lock resource to dynamic memory pool module;
For reading lock status action, whether first WORM operation logic layer is retrieved in Hash administration module according to Key has corresponding WORM logic lock to exist, do not exist and directly return to lock unused state, existence is read real data mode in WORM logic lock and is returned;
Above-mentioned everything all completes under system physical locks protection same, is not interrupted when ensureing everything operation, guarantees the multithreading security of this software module self.
4. operation method according to claim 3, is characterized in that: comprise following application call interface and relevant WORM logical program flow process:
Write lock status query interface: the WORM logic lock that inquiry Key specifies write lock status, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read and wherein write mark, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Read lock status poll interface: the read counter state of value of the WORM logic lock that inquiry Key specifies, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) found, read wherein read counter, assignment is to rreturn value
If d) do not found, rreturn value is directly set to 0, represent not lock
E) separate this modular system physical locks, return to rreturn value;
Trial adds writes lock interface: write lock for the WORM logic lock of Key appointment adds, if this WORM logic lock is added and reads or write lock, unsuccessfully return to vacation, or after successfully locking, return very, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create WORM logic lock, be set to vacation if create failed rreturn value, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock of just having set up, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added read lock or write lock, if add and lock, rreturn value is set to vacation
If f) can lock, write mark and be set to 1 realization and lock, rreturn value is set to very simultaneously
G) separate this modular system physical locks
H) check rreturn value, false if, represent to lock unsuccessful, function returns to vacation, directly finishes
If i) rreturn value is true, represent to write lock and add successfully, need to arrange unlimited endless loop, constantly call read lock status poll interface, detect whether all read locks are all removed, be 0 until obtain read counter, side jumps out circulation, returns true;
Determine to add and write lock interface: for adding, the WORM logic lock of Key appointment writes lock, if this WORM logic lock is added and is read or write lock, circular wait, until successfully lock, idiographic flow is as follows:
A) unlimited endless loop is set, constantly calls and attempt adding writing lock interface
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Lock interface is write in releasing: write lock for the WORM logic lock releasing that Key specifies, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, setting is write and is masked as 0, destroys this WORM logic lock, deletes this lock index, releasing resource from Hash administration module
E) separate this modular system physical locks, return;
Attempt read lock interface: for the WORM logic lock read lock that Key specifies, if this WORM logic lock is added and writes lock, unsuccessfully return to vacation, or after successfully locking, return very, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, attempt to create, if create failed rreturn value, vacation is set, jump to g)
If d) created successfully, this WORM logic lock index and Key are built to Key-Value pairing, be pushed to Hash administration module and manage, if Hash pushes unsuccessfully, destroy the WORM logic lock just having created, rreturn value is set to vacation, jumps to g)
If e) find or create successfully, check whether this lock has added to write lock, if locked, rreturn value is set to vacation
If f) can lock, read counter+1 is realized and being locked, rreturn value is set to very simultaneously
G) separate this modular system physical locks, return to rreturn value;
Determine read lock interface: for the WORM logic lock read lock of Key appointment, if this WORM logic lock is added and is write lock, circular wait, until successfully add read lock, idiographic flow is as follows:
A) unlimited endless loop is set, constantly calls trial read lock
B) circulation continuation of failure
C) circulation is jumped out in success, returns true;
Remove read lock interface: remove read lock for the WORM logic lock that Key specifies, idiographic flow is as follows:
A) add this modular system physical locks
B) carry out Hash according to Key and search, find corresponding WORM logic lock
If c) do not found, do not do anything
If d) found, read counter-1, if <=0 of read counter now destroys this WORM logic lock, deletes this lock index, releasing resource from Hash administration module
E) separate this modular system physical locks, return.
5. described in claim 1, the application call interface of the system that realizes in Key-Value type WORM lock pond, for all computer programming language routine calls with call operation system API ability, comprises C, C++, compilation, Java, C#, VB.
6. described in claim 1, the system that realizes in Key-Value type WORM lock pond provides the version of different operating system, realize spanning operation system platform function, can under Windows, Linux and some other class Unix platform, work, module product can be organized as following form, practical function output:
.h header file application development interface declaration definition
.Windows dll dynamic link library
.Linux with so dynamic link library of Unix like
.obj Object linking file
.lib static link library.
CN201210150721.1A 2012-05-15 2012-05-15 Key-Value type write-once read-many lock pool software module and running method thereof Expired - Fee Related CN102681892B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210150721.1A CN102681892B (en) 2012-05-15 2012-05-15 Key-Value type write-once read-many lock pool software module and running method thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210150721.1A CN102681892B (en) 2012-05-15 2012-05-15 Key-Value type write-once read-many lock pool software module and running method thereof

Publications (2)

Publication Number Publication Date
CN102681892A CN102681892A (en) 2012-09-19
CN102681892B true CN102681892B (en) 2014-08-20

Family

ID=46813861

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210150721.1A Expired - Fee Related CN102681892B (en) 2012-05-15 2012-05-15 Key-Value type write-once read-many lock pool software module and running method thereof

Country Status (1)

Country Link
CN (1) CN102681892B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104572568B (en) * 2013-10-15 2021-07-23 蚂蚁金服(杭州)网络技术有限公司 Read lock operation method, write lock operation method and system
CN105243101B (en) * 2015-09-17 2019-05-10 浪潮(北京)电子信息产业有限公司 The method and system that multi-controller concurrently accesses same compressed data file
US10713210B2 (en) * 2015-10-13 2020-07-14 Microsoft Technology Licensing, Llc Distributed self-directed lock-free RDMA-based B-tree key-value manager
CN105511969B (en) * 2015-11-25 2020-05-19 中国船舶工业系统工程研究院 Method for mutual exclusion between cross-process threads
CN108762940B (en) * 2018-04-12 2020-09-04 武汉斗鱼网络科技有限公司 Multithreading access method and device
US11556395B2 (en) * 2020-01-24 2023-01-17 Microsoft Technology Licensing, Llc Data race detection with per-thread memory protection
CN112631742B (en) * 2020-12-30 2023-10-31 上海金卓科技有限公司 Resource access authority management device, method and system
CN112929278B (en) * 2021-02-24 2022-07-22 深圳市吉祥腾达科技有限公司 Method and system for multi-core parallel fast forwarding of data packets by network communication equipment
CN113220458B (en) * 2021-05-26 2022-11-01 西安热工研究院有限公司 Real-time scheduling method and device for realizing load balance of database connection pool

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5860070A (en) * 1996-05-31 1999-01-12 Oracle Corporation Method and apparatus of enforcing uniqueness of a key value for a row in a data table
CN1545033A (en) * 2003-11-14 2004-11-10 清华大学 LUN CACHE method for FC-SAN memory system
CN1808389A (en) * 2006-02-20 2006-07-26 南京联创科技股份有限公司 Autonomous locking method based on shared memory for account background memory database
CN101252603A (en) * 2008-04-11 2008-08-27 清华大学 Cluster distributed type lock management method based on storage area network SAN

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5860070A (en) * 1996-05-31 1999-01-12 Oracle Corporation Method and apparatus of enforcing uniqueness of a key value for a row in a data table
CN1545033A (en) * 2003-11-14 2004-11-10 清华大学 LUN CACHE method for FC-SAN memory system
CN1808389A (en) * 2006-02-20 2006-07-26 南京联创科技股份有限公司 Autonomous locking method based on shared memory for account background memory database
CN101252603A (en) * 2008-04-11 2008-08-27 清华大学 Cluster distributed type lock management method based on storage area network SAN

Also Published As

Publication number Publication date
CN102681892A (en) 2012-09-19

Similar Documents

Publication Publication Date Title
CN102681892B (en) Key-Value type write-once read-many lock pool software module and running method thereof
US9935975B2 (en) Hard object: lightweight hardware enforcement of encapsulation, unforgeability, and transactionality
Boyland et al. Capabilities for sharing: A generalisation of uniqueness and read-only
Bu et al. A bloat-aware design for big data applications
America Inheritance and subtyping in a parallel object-oriented language
Alistarh et al. Threadscan: Automatic and scalable memory reclamation
US6421690B1 (en) Computer memory management system
US20210182266A1 (en) System and method for use of lock-less techniques with a multidimensional database
CN104239134A (en) Method and device for managing tasks of many-core system
CN107103253B (en) Disk sensitive information scanning system based on MPI AC (alternating Current) serial matching parallel algorithm
CN102047222A (en) Blocking and bounding wrapper for thread-safe data collections
Blanusa et al. Scalable fine-grained parallel cycle enumeration algorithms
CN112000670B (en) Multithreading program data unified management method and system and electronic equipment
CN103842986A (en) System and method for supporting a self-tuning locking mechanism in a transactional middleware machine environment
Blelloch et al. Concurrent reference counting and resource management in wait-free constant time
Jamshidi et al. Accelerating Graph Mining Systems with Subgraph Morphing
Nguyen et al. Understanding and combating memory bloat in managed data-intensive systems
Sheffi et al. The era theorem for safe memory reclamation
CN112506626A (en) Application program starting method, computer equipment and storage medium
US9002897B2 (en) Aspected interfaces and methods for synchronized containers and other data structures
Thomas Extensibility and reuse of object-oriented synchronization components
Rivera et al. Heapless: Dynamic data structures without dynamic heap allocator for rust
Zotov A Formal Model of Shared Semantic Memory for Next-Generation Intelligent Systems
US7680986B1 (en) Practical implementation of arbitrary-sized LL/SC variables
Ledru JSpace: implementation of a Linda system in Java

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
ASS Succession or assignment of patent right

Owner name: XI'AN TPRI POWER STATION INFORMATION TECHNOLOGY CO

Free format text: FORMER OWNER: XI'AN THERMAL POWER RESEARCH INSTITUTE CO., LTD.

Effective date: 20150423

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 710032 XI'AN, SHAANXI PROVINCE TO: 710075 XI'AN, SHAANXI PROVINCE

TR01 Transfer of patent right

Effective date of registration: 20150423

Address after: 710075 Xi'an City, Shaanxi province high tech Zone Torch Hotel, block B, 11

Patentee after: XI'AN TPRI POWER STATION INFORMATION TECHNOLOGY CO., LTD.

Address before: 710032 Xingqing Road, Shaanxi, China, No. 136, No.

Patentee before: Xi'an Thermal Power Research Institute Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140820

Termination date: 20180515