Invention content
This specification one or more embodiment describes a kind of method and apparatus, can reduce foundation connection, data pass
Defeated takes, and increases throughput of system.
According in a first aspect, providing the method for reading data that a kind of reading writes few system more.First operation system and second
Operation system is connected by network.Second operation system is to read to write few system more, and second operation system includes pipe
Device, database and at least one caching library are managed, at least one caching library is the distributed caching of database, and manager provides
Control to database and at least one distributed caching.First operation system is equipped with the manager of the second operation system
Client-side program;The method is executed by the client-side program.The method includes:Read requests are obtained, the reading is asked
It asks for reading the data in the second operation system;In the flrst mode, according to read requests, caching library address is determined, it is described
It caches library address and corresponds to the first caching library at least one caching library;According to caching library address, established with the first caching library
First connection;By this first connect to first caching library send read requests, read the first data.
In a kind of possible scheme, the method includes the second connection is established with manager under the second mode, and
By this second connect to manager send read requests, will pass through the second connection from least one distributed caching or data
Read the second data in library.It is further possible that in scheme, the method includes comparing the first data and the second data, according to than
Relatively result determines the availability of first mode.
Include mode switch the method includes client-side program, the method includes roots in a kind of possible scheme
According to mode switch, a mode reads of first mode and second mode access evidence is selected.At another it is further possible that scheme
In, the method includes switching the mode switch, to switch between the first mode and the second mode.
It is described according to read requests in a kind of possible scheme, determine that caching library address includes according to read requests, really
Determine key;According to key and key-value pair, caching library address is determined.
In a kind of possible scheme, the method includes first caching library can not hiting data in the case of, Xiang Guan
Manage the request that device sends reading database.
According to second aspect, a kind of digital independent device of the second operation system of access of first operation system is provided.The
One operation system is connected with the second operation system by network.Second operation system be read write few system, described the
Two operation systems include manager, database and at least one caching library, and at least one caching library is the distribution of database
Formula caches, and manager provides the control to database and at least one distributed caching.The digital independent device includes:It obtains
Unit is taken, is configured to obtain read requests, the read requests are used to read the data in the second operation system;Determination unit,
It is configured in the flrst mode, according to read requests, determines that caching library address, the caching library address correspond at least one slow
The first caching library in warehousing;First connection unit is configured to according to caching library address, with first at least one caching library
The first connection is established in caching library;First reading unit, be configured to by this first connect to first caching library send read requests,
Read the first data.
According to the third aspect, a kind of computer readable storage medium is provided, computer program is stored thereon with, when described
When computer program executes in a computer, enable computer execute first aspect method.
According to fourth aspect, a kind of server is provided, server includes storage device, network interface and processor, institute
It states processor and is communicatively coupled to the storage device and network interface, storage device is stored with the client journey of manager
Sequence, manager provide the control to database and at least one distributed caching, and at least one caching library is point of database
Cloth caches, and the processor can be used for executing client-side program, and then the method for realizing first aspect.
The method and apparatus provided by this specification embodiment can be greatly reduced taking for network, increase system throughput
Amount, improves the access speed of application, and reduce the load of database.
Specific implementation mode
Embodiments herein is described below in detail, examples of the embodiments are shown in the accompanying drawings, wherein from beginning to end
Same or similar label indicates same or similar module or module with the same or similar functions.Below with reference to attached
The embodiment of figure description is exemplary, and is only used for explaining the application, and should not be understood as the limitation to the application.
Fig. 1 is that the operation system that this specification discloses accesses the schematic diagram of a scenario for reading more to write few system.As shown in Figure 1, having
First operation system and the second operation system can be connected each other by network.First operation system for example with server A 1, A2,
A3 is representative.In one example, the first operation system is server cluster, each server work(having the same in cluster
Can, load-balanced server distributes to the request dynamic of user at corresponding server according to the loading condition of each server
Reason.
Second operation system is for example including manager B, database B-M0 and at least one caching library B-H1, B-H2, B-H3
And B-H4, it constitutes one and reads to write few system more.Wherein, caching library B-H1, B-H2, B-H3 and B-H4 is the distribution of database B-M0
Formula caches.Database B-M0 can be deployed in the server where manager, also can individually be disposed;Database B-M0 is stored with perhaps
Most evidences, it can provide the query capability of data by issuing service, naturally it is also possible to allow to write new data into;Management
Device B realizes the control to database B-M0, distributed caching B-H1, B-H2, B-H3 and B-H4.As needed, cache library B-H1,
B-H2, B-H3 and B-H4 can be stored at least part in the data of database B-M0, in one example, store number
According to the not variable data of those of library B-M0.Certainly, database B-M0 and each caching library can be with storage files, object, picture,
Video etc. is hereinafter referred to as with data for the sake of simplicity.
Manager B can by data fragmentation, the data of database B-M0 be distributed to multiple caching library B-H1, B-H2,
In B-H3 and B-H4.Following several rules may be used in data fragmentation:Section fragment, Hash (hash) fragment, time slot (slot)
Fragment.Certainly, it is also feasible that others, which are conducive to digital independent and the rule of write-in,.For Hash fragment, hash algorithm can
To use static Hashing and consistency Hash.For example, with data D, based on the total number N for caching library, pass through consistency Hash
Algorithm calculates the corresponding cryptographic Hash of data D, and corresponding caching library can be found according to cryptographic Hash.
Under a kind of possible scene, it is relevant between the business of the first operation system and the business of the second operation system or
Person has dependence, it is therefore desirable to access the data of the second operation system.For example, the first operation system is responsible for transaction, the second industry
Business system is responsible for membership information, and the first operation system confirms transaction by inquiring the membership information in the second operation system
Progress.
Server A 1-A3, manager B, database B-M0 and multiple caching library B-H1, B-H2, B-H3 and B-H4 usually divide
It is located on different server or communication equipment, but can also be arranged on same server or same communication equipment;When point
When being located on different server or communication equipment, gentle warehousing B-H1, the B- of server A 1-A3, manager B, database B-M0
The network connections such as internet, private network can be passed through between H2, B-H3 and B-H4.This specification is not restricted this.
Fig. 2 shows under scene shown in Fig. 1, according to the structure for accessing distributed caching by client of one embodiment
Schematic diagram.As shown in Fig. 2, the server A 1 in the first operation system is equipped with the client journey of manager in the second operation system
Sequence.Client-side program can load manager B, database B-M0 and its caching library B-H1, B- according to configuration information when mounted
The link address of H2, B-H3, B-H4 can also obtain corresponding link address from server-side.
Database B-M0 is primary database, can carry out the read-write operation of data to it.Cache library B-H1, B-H2, B-H3,
B-H4 is stored at least part data of database B-M0 according to slice rule respectively as the caching of primary database.Management
Device B is equipped with serve end program, realizes the control to database B-M0 and distributed caching B-H1, B-H2, B-H3 and B-H4,
And the access request in response to client, for its provide the read and write access to database B-M0 and to caching library B-H1, B-H2,
The read access of B-H3, B-H4.
Under a kind of access module, client-side program can complete the reading of data by the serve end program in manager
Write operation.According to the addresses manager B 0, the serve end program of client-side program and manager B establishes communication linkage L1.It is building
After vertical link L1, manager B, will be in new data or modification data write-in database B-M0 according to write request;It is grasped according to reading
Make and corresponding slice is regular, caching library (such as B-H3) hair into distributed caching B-H1, B-H2, B-H3 and B-H4
Read requests are played, server is returned to after the connection L1 ' between manager B eases up warehousing B-H3 reads data from the caching library
A1.It is this to be referred to as second mode in the description in such a way that data are read in remote service end access cache library.
According to this specification embodiment, under another access module, client-side program not by manager, and directly with
Connection is established in target cache library, to realize data access.Specifically, when the first operation system needs to read the second business system
When data in system, client-side program obtains read requests, and the read requests are used to read the data in the second operation system.
In one example, read requests carry the user identifier (USER ID, abbreviation UID) of user.Then, client-side program can root
According to read requests, caching library address is determined, which, which corresponds at least one caching library, can read data
Target cache library, such as B-H3;Then, according to the caching library addresses B-H3 3, connection L2 is established with caching library B-H3;Pass through the company
It meets L2 and sends read requests to caching library B-H3, read data.In one example, according to read requests determination key, then root
It postpones according to key and key-value pair and determines corresponding caching library address in warehousing address list.Specifically, client-side program can be advance
The hashed value in caching library is calculated, and each caching library is distributed on 0 to 2 circle of 32 powers;Upon receipt of a read request, objective
Family end program with same method calculate data to be read key hashed value and map to circle on, be mapped to from data to be read
Position start to search clockwise, read data from the caching library corresponding to first address found.Then, client
Program obtains query object according to the unserializing mode that caching library provides.It will be understood to those skilled in the art that caching library
Address can also be achieved other ways, such as to manager B inquire, client-side program is then supplied to by manager B.
The data reading mode that this client is directly interacted with distributed caching is referred to as the in the present specification
One pattern.Realize that an example of first mode is the client journey in the embedded caching library in the client-side program of the manager
Sequence or part of it.Fig. 7 is the schematic diagram for caching library client insertion manager client.Caching library client configuration in figure
There is caching library address list, such as the caching library address of B-H1 ... B-H4 is noted down in lists.In one example, in caching library
Number have increase and decrease in the case of, by the interaction between distributed caching library and its client, can timely update first
Caching library address list in operation system.
Taking for first mode is totally different in second mode.In a second mode for the path of middle A1/B/B-H3, data are read
Process include that 1 linked L1 of server A and manager B establishes communication, then manager B eases up the linked L1 ' of warehousing B-H3
Communication is established, then data warehousing B-H3 of postponing is transmitted to manager B again to server A 1, and network transmission therein, which takes, includes
Server A 1 and manager B establish connection, data transmission take and manager B established with distributed caching B-H3 connect,
Data transmission takes.In contrast to this, it includes only clothes that the mode of the access reading business of first mode takes in network transmission
Being engaged in, device A1 and distributed caching B3 establishes connection, data transmission takes, and can largely reduce taking for network, increases system throughput
Amount.
It is well known that caching library is also likely to be present the situation being not hit by.Fig. 3 illustrates to cache library in the flrst mode can not
The flow diagram of hiting data.As shown in figure 3, in step S32, first mode is taken in determination, is directly accessed by client
Cache library.In step S34, judge to cache library whether hiting data?If it is, entering step S37, data are read.If not,
Then enter step S36, instruction manager inquiry database or the other operations of execution.
Obviously, the first mode that client is directly interacted with distributed caching, and the second mode via server-side,
It is each has something to recommend him.Therefore, according to the embodiment of this specification, the ability for being selected and being switched between both of which is provided.Fig. 4
The method flow schematic diagram that distributed caching is accessed by client according to one embodiment is shown.The method of the embodiment carries
The ability of one key switching in some scenarios is supplied, the first mode or lead to that permission dynamic select is directly accessed by client
Cross the second mode of the remote service of server-side.This method can be to be subject on the basis of structure shown in scene shown in Fig. 1 and Fig. 2
It realizes.
As shown in figure 4, in step S42, client receives the request for reading data, and the read requests are for reading the
Data in two operation systems.Then, in step S44, client judges whether using double reading modes.If it is, in step
S46 opens double reading modes, reads result a by way of the direct access cache library of client in the flrst mode first, then
Result b is read by server-side access cache library under the second mode.Certainly, first mode and second mode at step S46
The sequence of the two can change, and can take first mode and the parallel access mode of second mode, can also first second
The access mode of first mode after pattern.In one example, it is compared after result a, b being carried out Hash, counts different numbers.
If result a, b there is no inconsistent, then illustrates that the first mode in the direct access cache library of client is available.Such verification machine
It is formed with and helps pinpoint the problems and solve the problems, such as in early period or in operation at 1 access cache library of server A.In addition, client
The different numbers counted can be periodically or non-periodically sent to manager, the different feelings of manager analyses and comparison result by end
Condition arranges corresponding measure, for example updates distributed caching early.
If not using double reading modes in step S44 judgements, in step S47, whether judgment model switch is opened.Such as
Fruit mode switch is opened, then enters step S49, and client reads data by remote service end under the second mode, that is, passes through
The mode in manager accesses caching library reads data.If switch is closed, S48 is entered step, in the flrst mode client
Direct access cache library is held, data are read.
By means of mode switch, client can neatly select according to the different load situation of the second operation system
One pattern or second mode.For example, in the case that the second operation system business is not busy or caching library hit rate is not high, client
Select work under the second mode;Second operation system heavy traffic or data need in the case of reading as early as possible, client
Select work in the flrst mode.
By means of mode switch, client can also dynamic and rapidly cut between the first mode and the second mode
It changes.
Business early period is being read, can judge the availability of first mode by double reading modes.If by verification first
Pattern is available, then first mode is opened in client selection, is directly read under caching library by client.The read in client
Under one pattern, client can continue according to monitoring and business throughput, the performance in the direct access cache library of verification client.Such as
There is local problem in the second operation system of fruit or network, interfere the normal work of first mode, can be switched with fast-switching mode,
So that client operation is under the second mode, caching library is remotely accessed by server-side, it is direct greatly to reduce cache client
The risk in access cache library;After problem is eliminated, it can be switched with switch mode so that client comes back to first mode.Mould
Formula switch can help to realize the seamless switching in business procedure, be not necessarily to staff on duty.
Under a possible embodiment, the first operation system is server cluster, and each of cluster services utensil
There are identical function, load-balanced server to be distributed to the request dynamic of user accordingly according to the loading condition of each server
Server process.Each server in cluster is integrated with the client-side program of the manager of the second operation system, and configures
There is mode switch, client-side program can be made to switch in the first mode and in a second mode.Pattern in cluster in each server
Switch, can also independently be switched as the case may be with synchronism switching.In one example, for Support Mode switching
Safety can configure one in the first operation system or a small number of servers, its mode switch is made to be switched to the first mould in advance
Under formula, pass through the direct access cache library of client.If by this or these work of server whithin a period of time
Monitoring finds that first mode works normally, then can the first mould be switched to the mode switch of each server in entire cluster
Under formula, or it is made to be switched under first mode gradually.
Although the first mode in the direct access cache library of client helps fast to read data, due to database with
Caching library is difficult to ensure data consistency, therefore, it is necessary to the distributed caching that timely updates.In a possible realization method
In, a more new task is written in the manager of the second operation system while updating the data library, by means of this more new task energy
Ensure the transaction consistency with operation data.More new task can be driven by timed task, be supervised in each distributed caching with this
The content of node all updates, incremental data problem when preventing concurrent.
Fig. 5 illustrates to can be used for realizing that the first operation system of above-mentioned various technologies respectively takes according to this specification embodiment
The detailed structure view of business device.The block diagram shows the hardware foundations of method flow shown in principle shown in achievable Fig. 2 and Fig. 4.
As shown in figure 5, server may include processor 102, which indicates the microprocessor of the overall operation for controlling server
Device or controller 111.Data/address bus 115 can be conducive to carry out data between storage device 140, processor 102 and controller 117
Transmission.Controller 111 can be used for interacting and controlling it with distinct device by equipment controlling bus 117.
Server further includes storage device 140, which can store client-side program;Can also store database and
It caches the access address in library.Terminal device may also include random access memory (RAM) 120 and read-only memory (ROM)
122.ROM 122 can store pending program, utility program or process, such as operating system in a non-volatile manner.
RAM120, also referred to as memory, it is possible to provide volatile data storage, and the instruction of storage running operating system and client-side program and
Its relevant data.
In operation, client application is loaded on from RAM140 in RAM120, and thus control processor 102
Corresponding operating is executed, thus client is able to access distributed caching, to read data therein.
In one example, client application obtains read requests, and the read requests are for reading the second business
Data in system;In the flrst mode, according to read requests, determine that caching library address, the caching library address correspond to extremely
The first caching library in few caching library;According to caching library address, establishes first with the first caching library and connect;By this first
It connects to the first caching library and sends read requests, read the first data.In another example, under the second mode, client
Application program and manager establish the second connection, and second connect to manager by this and send read requests, will pass through
Second connection reads the second data from least one distributed caching.Certainly, client application can compare the first data
With the second data, the availability of first mode is determined according to comparison result.
It should be appreciated that server described herein can utilize previously described embodiment of the method or therewith at many aspects
In conjunction with.
Fig. 6 is a kind of structural schematic diagram of device provided in an embodiment of the present invention.Device corresponds to front at many aspects
The step of embodiment of the method for description, is in combination, and the modules of device can be by software, hardware or hardware and software
Combination is realized.Specifically, which may include acquiring unit 200, be configured to obtain read requests, the read requests are used
In reading the data in the second operation system;It can also include determination unit 202, be configured to, according to read requests, determine caching
Library address, the caching library address correspond to the first caching library at least one caching library;First connection unit 204, configuration
According to caching library address, to establish first with the first caching library at least one caching library and connecting;First reading unit 206,
Be configured to by this first connect to first caching library send read requests, read the first data.Note that determination unit 202,
One connection unit 204, the work of the first reading unit 206 are in the flrst mode.
In a possible scheme, digital independent device includes the second connection unit 212, is configured to establish with manager
Second connection;With, the second reading unit 214, it is configured to second connect to manager by this and send read requests, will pass through
Second connection reads the second data from least one distributed caching.Second connection unit 212 and the work of the second reading unit 214
Under the second mode different from first mode.It is further possible that in scheme, digital independent device includes that first mode can
It with property determination unit 226, is configured to compare the first data and the second data, first mode availability is determined according to comparison result.
At another it is further possible that in scheme, digital independent device includes mode switch 238;In one example, mode switch
The mode reads access evidence of 238 selection first modes and second mode;In another example, the mode switch 238 exists
It is switched between first mode and second mode.
In a possible scheme, the determination unit includes key determination unit, is configured to, according to read requests, determine
Key;Address determination unit is configured to, according to key and key-value pair, determine caching library address.
In a possible scheme, the digital independent device further includes third reading unit, first caching library without
In the case of method hiting data, the request of reading database is sent to manager.
According to the embodiment of another aspect, a kind of computer readable storage medium is also provided, is stored thereon with computer journey
Sequence enables computer execute and combines method described in Fig. 2 and Fig. 4 when the computer program executes in a computer.
Those skilled in the art are it will be appreciated that in said one or multiple examples, work(described in the invention
It can be realized with hardware, software, firmware or their arbitrary combination.It when implemented in software, can be by these functions
Storage in computer-readable medium or as on computer-readable medium one or more instructions or code be transmitted.
Above-described specific implementation mode has carried out further the purpose of the present invention, technical solution and advantageous effect
It is described in detail, it should be understood that the foregoing is merely the specific implementation mode of the present invention, is not intended to limit the present invention
Protection domain, all any modification, equivalent substitution, improvement and etc. on the basis of technical scheme of the present invention, done should all
Including within protection scope of the present invention.