CN107689977B - Routing method and system for distributed caching and pushing - Google Patents

Routing method and system for distributed caching and pushing Download PDF

Info

Publication number
CN107689977B
CN107689977B CN201610638721.4A CN201610638721A CN107689977B CN 107689977 B CN107689977 B CN 107689977B CN 201610638721 A CN201610638721 A CN 201610638721A CN 107689977 B CN107689977 B CN 107689977B
Authority
CN
China
Prior art keywords
partition
value
connection
key value
returning
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.)
Active
Application number
CN201610638721.4A
Other languages
Chinese (zh)
Other versions
CN107689977A (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.)
Xiamen Yaxon Networks Co Ltd
Original Assignee
Xiamen Yaxon Networks Co Ltd
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 Xiamen Yaxon Networks Co Ltd filed Critical Xiamen Yaxon Networks Co Ltd
Priority to CN201610638721.4A priority Critical patent/CN107689977B/en
Publication of CN107689977A publication Critical patent/CN107689977A/en
Application granted granted Critical
Publication of CN107689977B publication Critical patent/CN107689977B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/44Distributed routing
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/55Push-based network services

Abstract

The invention discloses a routing method and a system for distributed caching and pushing, wherein the method comprises the following steps: presetting a matching strategy of a request and a partition sent by a requester through a class interface, wherein the request comprises a service parameter and a partition parameter; receiving a request sent by a requester; according to the partition parameters and the matching strategy, performing partition routing to obtain a partition set comprising at least one partition; generating an access strategy according to the partition set; acquiring the connection corresponding to each partition in the partition set in the distributed cache partition according to the partition set and the corresponding access strategy; accessing the corresponding partition according to the connection to obtain a corresponding return result; and feeding back the return result to the requester. The invention has the advantages of high performance, high expansibility, high availability, high usability and the like.

Description

Routing method and system for distributed caching and pushing
Technical Field
The invention relates to the technical field of partition routing, in particular to a routing method and a system for distributed caching and pushing.
Background
With the advent of the big data age, distributed caching and pushing has become an indispensable solution for many distributed architectures in order to relieve the I/O pressure of traditional databases. And the vertical/horizontal expansion of the service, the regular dynamic routing, the high availability of the caching and pushing nodes, the usability thereof and the like in terms of distributed caching and pushing become the focus of much attention.
The traditional distributed relaxation push routing client framework has limitations, most of the traditional distributed relaxation push routing client frameworks only realize simple partition routing, can meet functions on an application layer to a certain extent, but cannot meet multi-style routing on service vertical/horizontal expansion, and depend on a third-party disaster tolerance tool in the aspect of high availability of each routing node, and the third-party disaster tolerance tool needs to be deployed independently, so that the steps are complex, the usability is low, and the requirement on application personnel is high.
In the chinese patent publication with publication number CN105357314A, a fixed-point distributed cache system and a cache method thereof are proposed, which include a cache configuration module, a cache refresh module, a service data response module, a cache storage module and a plurality of storage servers, where a cache policy is configured in the storage servers of each storage node, and when a user sends a data request to a storage server that has accessed the same network domain, the node takes out the service data in a background server database and performs cache synchronization update. Although the scheme can realize the partitioned storage, the data can only be randomly scattered in each storage server, the special data division cannot be realized, and the storage and the acquisition of the cache information can only be carried out according to a single key value.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the routing method and system for distributed caching and pushing have the advantages of high performance, high expansibility, high availability, high usability and the like.
In order to solve the technical problems, the invention adopts the technical scheme that: a routing method for distributed caching and pushing comprises the following steps:
presetting a matching strategy of a request and a partition sent by a requester through a class interface, wherein the request comprises a service parameter and a partition parameter;
receiving a request sent by a requester;
according to the partition parameters and the matching strategy, performing partition routing to obtain a partition set comprising at least one partition;
generating an access strategy according to the partition set;
acquiring the connection corresponding to each partition in the partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
accessing the corresponding partition according to the connection to obtain a corresponding return result;
and feeding back the return result to the requester.
The invention also relates to the invention and provides a distributed cache and push routing system, which comprises:
the system comprises a presetting module, a judging module and a judging module, wherein the presetting module is used for presetting a matching strategy of a request and a partition sent by a requester through a class interface, and the request comprises a service parameter and a partition parameter;
the receiving module is used for receiving a request sent by a requester;
the partition routing module is used for carrying out partition routing according to the partition parameters and the matching strategy to obtain a partition set comprising at least one partition;
the generating module is used for generating an access strategy according to the partition set;
the first acquisition module is used for acquiring the connection of each partition in the corresponding partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
the second acquisition module is used for accessing the corresponding partition according to the connection and acquiring the corresponding return result;
and the feedback module is used for feeding back the return result to the requester.
The invention has the beneficial effects that: by presetting the matching strategy of the request and the partition, the expansion of distributed caching and pushing in the vertical and horizontal directions is realized, and various high-performance dynamic routing partition modes of caching information storage, pushing and subscription are supported; according to different partition sets, different access strategies are adopted, so that the efficiency and the quality of partition access can be improved; the distributed cache and push routing architecture with high performance, high expansibility, high availability and high usability can be realized.
Drawings
FIG. 1 is a flow chart of a distributed caching and push routing method of the present invention;
fig. 2 is a schematic structural diagram of a routing architecture according to a first embodiment of the present invention;
FIG. 3 is a flowchart of a step S4 according to an embodiment of the present invention;
FIG. 4 is a flowchart of a step S5 according to an embodiment of the present invention;
FIG. 5 is a flowchart of a second step S3 according to an embodiment of the present invention;
FIG. 6 is a flowchart of a method according to a third embodiment of the present invention;
FIG. 7 is a schematic diagram of a distributed caching and pushing routing system;
fig. 8 is a schematic structural diagram of a system according to a fifth embodiment of the present invention.
Description of reference numerals:
100. a comprehensive service interface management module; 200. a routing partition rule configuration module; 300. a route partition analysis module; 400. a partition access policy module; 500. a partition connection pool management module; 600. a partition fault sensing module; 700. distributed cache partition nodes;
1. presetting a module; 2. a receiving module; 3. a partition routing module; 4. a generation module; 5. a first acquisition module; 6. a second acquisition module; 7. a feedback module; 8. a detection module; 9. a third obtaining module; 10. selecting a main module;
101. a first association unit; 102. a second association unit; 103. a third association unit;
301. a first judgment unit; 302. a first returning unit; 303. a second judgment unit; 304. a second returning unit; 305. a third returning unit; 306. a first acquisition unit; 307. a third judgment unit; 308. a fourth returning unit; 309. a calculation unit; 310. a rounding unit; 311. a fourth judgment unit; 312. a fifth returning unit; 313. dividing the cells; 314. a first execution unit; 315. a splitting unit; 316. a second execution unit; 317. a third execution unit; 318. a de-coincidence unit;
401. a sixth returning unit; 402. a fifth judging unit; 403. a seventh returning unit; 404. an eighth returning unit;
501. a first receiving unit; 502. a sixth judgment unit; 503. a ninth returning unit; 504. a seventh judging unit; 505. a tenth returning unit; 506. a waiting unit; 507. an eleventh returning unit;
1001. a second acquisition unit; 1002. an arithmetic unit; 1003. a fourth association unit; 1004. a sorting unit; 1005. a third acquisition unit; 1006. an eighth judging unit; 1007. a closing unit; 1008. a fourth acquisition unit; 1009. a removing unit; 1010. and a fourth execution unit.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: and associating the partition with the naming space of the class interface, the command variable and the routing key value in the request to realize multi-style routing on vertical and horizontal extension of the service.
Referring to fig. 1, a routing method for distributed caching and pushing includes:
presetting a matching strategy of a request and a partition sent by a requester through a class interface, wherein the request comprises a service parameter and a partition parameter;
receiving a request sent by a requester;
according to the partition parameters and the matching strategy, performing partition routing to obtain a partition set comprising at least one partition;
generating an access strategy according to the partition set;
acquiring the connection corresponding to each partition in the partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
accessing the corresponding partition according to the connection to obtain a corresponding return result;
and feeding back the return result to the requester.
From the above description, the beneficial effects of the present invention are: the method has the advantages of high performance, high expansibility, high availability, high usability and the like.
Further, the "matching policy between the request sent by the preset requester through the class interface and the partition" specifically includes:
associating the unique identifier of the partition with a naming space of the class interface according to a preset rule to obtain a first association relation;
associating the unique identifier of the partition, the name space of the class interface and the command variable in the class interface according to a preset rule to obtain a second association relation;
and associating the unique identifier of the partition, the naming space of the class interface and the routing key value in the partition parameter according to a preset rule to obtain a third association relation.
Further, the "performing partition routing according to the partition parameter and the matching policy to obtain a partition set including at least one partition" specifically includes:
judging whether the partition parameters comprise routing key values or not;
if not, returning the corresponding partition according to the first incidence relation or the second incidence relation;
if yes, judging the type of the key value parameter of the routing key value;
if the type of the key value parameter is a null value, returning to a preset default partition;
if the type of the key value parameter is a single key value, performing single value matching according to the third association relation, and returning to the corresponding partition;
if the type of the key value parameter is a continuous key value in a closed interval range, performing single-value matching on the minimum value and the maximum value in the closed interval respectively according to the third correlation, and acquiring a partition corresponding to the minimum value and a partition corresponding to the maximum value;
judging whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value;
if the two are consistent, returning the partition corresponding to the minimum value or the partition corresponding to the maximum value;
if not, calculating the average of the minimum value and the maximum value;
if the average is not an integer, rounding the average downwards;
determining whether the average is equal to a minimum value;
if so, returning the partition corresponding to the minimum value and the partition corresponding to the maximum value;
if not, dividing the closed interval into two closed intervals according to the average number;
respectively returning and executing the step of respectively performing single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation to obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
if the type of the key value parameter is a multi-hybrid key value, splitting the multi-hybrid key value to obtain a single key value and continuous key values in a closed interval range;
for a single key value, executing the step if the type of the key value parameter is the single key value;
for the continuous key values in the closed interval range, executing the step if the type of the key value parameter is the continuous key value in the closed interval range;
and if the plurality of partitions are returned, performing de-coincidence on the plurality of partitions to obtain a partition set.
From the above description, it can be seen that the vertical and horizontal expansion of distributed caching and pushing can be realized, and a variety of high-performance dynamic routing partition modes of cache information storage, pushing and subscription are supported.
Further, the "generating an access policy according to the partition set" specifically includes:
if the number of the partitions in the partition set is one, returning a sequential access strategy;
if the number of the partitions in the partition set is more than one, judging whether the service parameters comprise transaction sequence flag variables;
if so, returning the sequential access strategy;
if not, returning the concurrent access strategy.
As can be seen from the above description, by adopting different access policies according to the number of different partitions and requests, the access efficiency and quality can be improved.
Further, the "obtaining the connection corresponding to each partition in the partition set in the distributed cache partition" specifically includes:
receiving a request for acquiring partition connection;
judging whether the connection pool of the partition has idle connection;
if yes, returning to the idle connection;
if not, judging whether the connection number in the connection pool of the partition exceeds a preset maximum connection number or not;
if not, creating a new connection in the connection pool of the partition, and returning to the new connection;
if yes, waiting for the connection being used to be released;
and if the waiting time exceeds the preset maximum waiting time, returning to the empty connection.
Further, before the "accessing the corresponding partition according to the connection", the method further includes:
detecting the running state of each partition main service in the distributed cache partition according to preset monitoring time;
if the main service of a partition is detected to be out of order, acquiring the slave service in the partition;
and selecting one slave service from the slave services as a new master service according to a master selection algorithm.
Further, the "selecting one slave service from the slave services as a new master service according to a master selection algorithm" specifically includes:
acquiring ip addresses and port numbers of the master service and the slave service in the partition;
carrying out hash operation on the instance name of the slave service to obtain a corresponding integer value;
respectively associating an ip address and a port of a slave service and an integer value corresponding to the slave service to obtain an association relation set;
sorting the incidence relation set according to the integer value;
acquiring a first incidence relation in the incidence relation set;
judging whether the slave service corresponding to the first incidence relation is alive or not;
if so, closing the connection in the connection pool corresponding to the partition according to the ip address and the port number of the main service; according to the ip address and the port number of the slave service, connection is obtained again and stored in the corresponding connection pool;
if not, removing the first incidence relation in the incidence relation set; and continuing to execute the step of obtaining the first incidence relation in the incidence relation set.
According to the above description, by automatically performing fault detection on each partition, manual configuration is not required when the node fault is recovered; invalid or aged partition connections can be updated in time, high availability is achieved on the basis of a redundancy mechanism, single-point failure is avoided, automatic discovery of faults is supported, and fault switching is transparently implemented.
Referring to fig. 7, the present invention further provides a distributed caching and pushing routing system, including:
the system comprises a presetting module, a judging module and a judging module, wherein the presetting module is used for presetting a matching strategy of a request and a partition sent by a requester through a class interface, and the request comprises a service parameter and a partition parameter;
the receiving module is used for receiving a request sent by a requester;
the partition routing module is used for carrying out partition routing according to the partition parameters and the matching strategy to obtain a partition set comprising at least one partition;
the generating module is used for generating an access strategy according to the partition set;
the first acquisition module is used for acquiring the connection of each partition in the corresponding partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
the second acquisition module is used for accessing the corresponding partition according to the connection and acquiring the corresponding return result;
and the feedback module is used for feeding back the return result to the requester.
Further, the preset module comprises:
the first association unit is used for associating the unique identifier of the partition with the namespace of the class interface according to a preset rule to obtain a first association relation;
the second association unit is used for associating the unique identifier of the partition, the name space of the class interface and the command variable in the class interface according to a preset rule to obtain a second association relation;
and the third association unit is used for associating the unique identifier of the partition, the namespace of the class interface and the routing key value in the partition parameter according to a preset rule to obtain a third association relation.
Further, the partition routing module comprises:
the first judging unit is used for judging whether the partition parameters comprise routing key values or not;
the first returning unit is used for returning the corresponding partition according to the first incidence relation or the second incidence relation if the partition is not in the first association relation or the second association relation;
the second judging unit is used for judging the type of the key value parameter of the routing key value if the key value parameter is the same as the type of the key value parameter of the routing key value;
the second returning unit is used for returning to a preset default partition if the type of the key value parameter is a null value;
a third returning unit, configured to, if the type of the key value parameter is a single key value, perform single value matching according to the third association relationship, and return to the corresponding partition;
the first obtaining unit is used for respectively carrying out single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation relationship if the type of the key value parameter is a continuous key value in the closed interval range, and obtaining a partition corresponding to the minimum value and a partition corresponding to the maximum value;
a third judging unit, configured to judge whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value;
the fourth returning unit is used for returning the partition corresponding to the minimum value or the partition corresponding to the maximum value if the two are consistent;
the calculating unit is used for calculating the average of the minimum value and the maximum value if the minimum value and the maximum value are inconsistent;
a rounding unit, configured to round the average downwards if the average is not an integer;
a fourth judging unit configured to judge whether the average is equal to a minimum value;
a fifth returning unit, configured to return, if yes, the partition corresponding to the minimum value and the partition corresponding to the maximum value;
the dividing unit is used for dividing the closed interval into two closed intervals according to the average number if the closed interval is not the same as the average number;
the first execution unit is used for respectively returning and executing the steps of respectively performing single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation to obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
the splitting unit is used for splitting the multiple mixed key values to obtain single key values and continuous key values in a closed interval range if the type of the key value parameter is the multiple mixed key values;
a second execution unit, configured to execute, for a single key value, the step that is performed if the type of the key value parameter is the single key value;
a third execution unit, configured to execute, for a continuous key value within a closed interval range, the step that if the type of the key value parameter is the continuous key value within the closed interval range;
and the de-coincidence unit is used for performing de-coincidence on the plurality of partitions to obtain a partition set if the plurality of partitions are returned.
Example one
The first embodiment of the invention is as follows: a routing method for distributed caching and pushing, the method is based on a routing architecture shown in fig. 2, and includes an integrated service interface management module 100, a routing partition rule configuration module 200, a routing partition parsing module 300, a partition access policy module 400, and a partition connection pool management module 500, where the integrated service interface management module 100 is connected to an external application layer, the routing partition rule configuration module 200 is connected to the routing partition parsing module 300, the partition access policy module 400, and the partition connection pool management module 500 are respectively connected to the integrated service interface management module 100, and the partition connection pool management module 500 is connected to a distributed caching partition node 700; the system further comprises a partition fault sensing module 600, and the partition fault sensing module 600 is respectively connected with the partition connection pool management module 500 and the distributed cache partition node 700.
The integrated service interface management module 100 belongs to the entry module of the present invention, and is responsible for receiving the request of the application layer. And externally, a cache storage, pushing and subscribing interface based on various routing key value pairs is provided. The routing key values of the interfaces support 4 types, specifically comprising null key values, single key values, continuous key values in a closed interval range and mixed use of multiple key values. And internally and efficiently acquiring a routing partition and a partition access strategy by utilizing a thread pool concurrent strategy, acquiring partition connection and initiating access, supporting a result returned by an internal integration partition, and finally returning an integrated result set to an application layer.
The routing partition rule configuration module 200 loads information of a routing configuration rule once when the system is started, and after the configuration rule occurs, the routing partition rule configuration module 200 intelligently senses and reloads the routing configuration rule.
The partition access policy module 400 is responsible for providing policies for accessing partitions, including sequential access policies and concurrent access policies; the sequential access strategy is that the same thread accesses each partition according to the sequence, namely under the condition of a plurality of partitions, the access is sequenced one by one according to the default of the partition, and if the access of one partition is abnormal in the middle of the access, the subsequent access is interrupted; the concurrent access strategy is that different threads simultaneously access each partition, that is, under the condition of a plurality of partitions, the concurrent access strategy simultaneously accesses a plurality of partitions in a multi-thread concurrent manner.
The partition connection pool management module 500 manages the connections of all partitions. A connection pool is established for each partition in the module, and each time the partition is accessed, the available connection is taken out from the connection pool corresponding to the partition. The connection pools of all partitions follow a uniform configuration. The configurable parameters are: the maximum connection number, the maximum idle connection number, the maximum waiting connection time, the maximum idle connection time and the connection detection time interval are defined as follows:
maximum number of connections: the maximum number of connections accommodated by the partition connection pool;
maximum number of idle connections: namely, the maximum number of connections in the idle state of the partition is connected, if the number of the connections in the idle state is found to exceed the maximum idle time parameter of the connections at the detection time point (the judgment standard of the idle state is that the current connections are not practical within the maximum idle time parameter of the connections), the redundant idle connections are closed, and the occupation of resources is reduced;
maximum wait connection time: that is, the time for acquiring connection from the connection pool every time, if the connection is not acquired after the time, the connection is regarded as failed to be acquired, and an exception is returned;
connection maximum idle time: the method is used for judging whether the connection is in an idle state or not, and if the connection is not practical after the parameter time is exceeded, the connection is judged to be in the idle state;
connection detection time interval: for configuring how often to detect an idle connection.
The partition failure sensing module 600 is responsible for monitoring the availability of each partition, performing disaster recovery switching on the failed partition, and notifying the partition connection pool management module 500 to update the connection in the connection pool where the failed partition is located.
The working principle of the whole routing architecture is as follows:
the integrated service interface management module receives a request of an application layer, and sends the request to a routing partition analysis module after logical judgment and conversion;
the route partition analysis module receives the request, performs partition analysis according to the configuration rule in the route partition rule configuration module, and returns a partition set meeting the condition to the comprehensive service interface management module;
the comprehensive service interface management module receives and consults a partition access strategy module for a strategy of accessing the partition according to the partition set;
the partition access strategy module returns an optimal access strategy to the comprehensive service interface management module;
and the comprehensive service interface management module receives and acquires corresponding partition connection through the partition connection pool management module according to the access strategy, initiates access to the partition and acquires a final result.
Referring to fig. 1, the method of the present embodiment includes the following steps:
s1: presetting a matching strategy of a request and a partition sent by a requester through a class interface, wherein the request comprises a service parameter and a partition parameter; the service parameters comprise service data to be stored or pushed and transaction sequence flag variables for identifying whether the service data have a certain sequence arrangement; the partition parameter includes a routing key, that is, an identifier of each corresponding service data, for example, the routing key of the vehicle service is a vehicle id.
S2: receiving a request sent by a requester; when a request is received, the validity of the parameters of the request can be judged.
S3: and performing partition routing according to the partition parameters and the matching strategy to obtain a partition set comprising at least one partition.
S4: and generating an access strategy according to the partition set.
S5: and acquiring the connection of each partition in the corresponding partition set in the distributed cache partition according to the partition set and the corresponding access strategy.
S6: and accessing the corresponding partition according to the connection to obtain a corresponding return result.
S7: feeding back the return result to the requester; the returned results may also be integrated before being fed back to the requesting party.
As shown in fig. 3, step S4 includes the following steps:
s401: and judging whether the number of the partitions in the partition set is one, if so, executing step S403, and if not, executing step S402.
S402: and judging whether the business parameters comprise a transaction sequence flag variable, if so, executing a step S403, and if not, executing a step S404.
S403: and returning the sequential access policy.
S404: and returning the concurrent access policy.
As shown in fig. 4, step S5 includes the following steps:
s501: a request to obtain partition connections is received.
S502: and judging whether the connection pool of the partition has idle connection, if so, executing step S503, and if not, executing step S504.
S503: and returning to the idle connection.
S504: and judging whether the connection number in the connection pool of the partition exceeds a preset maximum connection number, if not, executing step S505, and if so, executing step S506.
S505: and creating a new connection in the connection pool of the partition, and returning the new connection.
S506: waiting for the connection being used to be released, executing step S502; and if the waiting time exceeds the preset maximum waiting time, returning to the empty connection.
The embodiment can realize a distributed cache and push routing architecture with high performance, high expansibility, high availability and high usability.
Example two
This embodiment is a further development of steps S1 and S3 in the first embodiment.
In step S1, the matching policy is a configuration rule, and includes the following partitioning manners:
a. and (3) based on the vertical partition type partition of the naming space, namely, associating the unique identifier of the partition with the naming space of the class interface according to a preset rule to obtain a first association relation. The unique identification of a partition may be a partition id. Based on the partition mode, one class interface can represent one class of service, different classes of services can be divided in a specific service scene, one application service corresponds to one class interface, and data of different services can be regularly divided into a certain partition by configuring the relation between the class interface and the partition id, so that the vertical division on the service data is realized.
For example, an interface class a1 is defined for the application service of the vehicle, and the namespace in which the interface class a1 is located is configured to correspond to the partition R1; the application service of the user is defined as an interface class A2, and the namespace in which the interface class A2 is located is configured to correspond to the partition R2. When the user calls the interface class to access the partition, partition matching is carried out through the namespace of the interface class, so that the data cache information of the vehicle application service is in the R1 partition, and the cache information of the user application service is in the R2 partition.
b. And (3) reading and writing the separated partition based on the command variable, namely, associating the unique identifier of the partition, the name space of the class interface and the command variable in the class interface according to a preset rule to obtain a second association relation. The partition mode is realized by expanding on the basis of a partition mode and further configuring the matching relation between the command variables and the partitions under the interface class name space on the basis of the a partition mode.
Taking the application service of the vehicle as an example, a vehicle application service interface class is defined, and the difference from the partition mode a is that each specifically called method of the vehicle application service interface class corresponding to the mode has a command variable corresponding to the command variable. The partition mode realizes the routing partition by configuring the corresponding relation between command variables and partitions. For example, in a vehicle application service interface class, a method for reading vehicle cache data is hooked with a command variable read under the same namespace, a method for writing the cache is hooked with a command variable write under the same namespace, a read command variable corresponds to a partition R1, a write command variable corresponds to a partition R2, and a partition R1 and a partition R2 need to perform data synchronization (that is, R1 and R2 both serve as cache data of vehicle services), when a program calls an interface class of the vehicle service to access the cache, which method of the interface class is called first, the command variable corresponding to the method is further analyzed, and finally, the partition corresponding to the command variable is analyzed, so that the partition to be accessed finally is determined. Because the method of each service interface class corresponds to the variables of the interface class under the same name space, different interface classes can define the same command variables, and mutual conflict can not be generated.
c. And based on the horizontal cutting type partition of the naming space, associating the unique identifier of the partition, the naming space of the class interface and a routing key value in the partition parameter according to a preset rule to obtain a third association relation. The partition mode is expanded on the basis of a partition mode, and on the basis of the partition mode, the horizontal segmentation is realized by further configuring the corresponding relation between the values of the routing keys and the partitions.
Taking the application service of the vehicle as an example, on the basis of configuring the namespace and the partition of the vehicle application service interface class, the corresponding relation between the vehicle id and the partition is further configured. For example, a vehicle application service interface class a1 is defined, a partition corresponding to the interface class is configured as R1 (as a default partition of vehicle service), and on this basis, a corresponding relationship between a vehicle id and a partition is further configured, for example, the vehicle id is in the partition R1 of 1-30000, and the vehicle id is in the partition R2 of 30001-60000 (configuration of the vehicle id and the partition id may also be performed according to other rules, for example, a value obtained by hashing the vehicle id is configured corresponding to the partition, or a matching rule for customizing the vehicle id and the partition, etc.). When the vehicle application service interface class is called, the incoming vehicle id is subjected to matching partition, if the proper partition cannot be matched according to the vehicle id, or the vehicle id is not incoming during interface calling, the default partition matched with the vehicle service, namely R1, is defaulted.
e. The partition is combined in various modes: a, b and c are combined; the horizontal cutting branch supports regular and irregular hash distribution of the same service data, the hash rule supports range, modulus, hash and the like to carry out hash distribution, and also supports a user-defined method to carry out hash.
Based on the matching policy, referring to fig. 5, step S3 includes the following steps:
s301: and judging whether the partition parameters include a routing key value, if not, executing the step S302, and if so, executing the step S303.
S302: returning to the corresponding partition according to the first incidence relation or the second incidence relation; namely, the partition routing is directly carried out according to the naming space or the naming variable called by the interface.
S303: and judging whether the type of the key value parameter of the routing key value is a null value, if so, executing step S304, and if not, executing step S305.
S304: and returning to the preset default partition.
S305: and judging whether the type of the key value parameter of the routing key value is a single key value, if so, executing a step S306, and if not, executing a step S307.
S306: and performing single value matching according to the third association relation, and returning to the corresponding partition.
S307: and judging whether the type of the key value parameter of the routing key value is a continuous key value in a closed interval range, if so, executing the step S308, and if not, executing the step S315.
S308: and respectively carrying out single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation, and obtaining a partition corresponding to the minimum value and a partition corresponding to the maximum value.
S309: and judging whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value, if so, executing the step S310, and if not, executing the step S311.
S310: and returning the partition corresponding to the minimum value or the partition corresponding to the maximum value.
S311: calculating an average of the minimum and maximum values; further, if the average is not an integer, rounding down the average.
S312: it is determined whether the average is equal to the minimum value, if so, step 313 is performed, and if not, step 314 is performed.
S313: and returning the partition corresponding to the minimum value and the partition corresponding to the maximum value, namely returning two partitions. For example, the closed interval is [5,6], the minimum value is 5, the maximum value is 6, the average number is 5.5, and when the average number is rounded down to 5, the average number is equal to the minimum value, and meanwhile, as can be seen from the above steps, the partition corresponding to 5 and the partition corresponding to 6 are not consistent, so two partitions corresponding to 5 and 6 are returned.
S314: and dividing the closed interval into two closed intervals according to the average number. For example, the occlusion interval is [1,10], the minimum is 1, the maximum is 10, the average is 5.5, the rounding is 5, the average is not equal to the minimum, thus dividing the occlusion interval [1,10] into [1,5] and [5,10 ]. At this time, steps S308 to S314 are respectively performed on the two divided closed intervals, that is, the above algorithm for the continuous key values in the closed interval range of the type of the key value parameter is recursively called.
S315: namely, the type of the key value parameter is a plurality of mixed key values, and the plurality of mixed key values are split to obtain a single key value and continuous key values in a closed interval range.
S316: and selecting the single key value obtained after splitting, calling the algorithm for the key value parameter with the type of the single key value, and executing the step S306.
S317: and selecting the continuous key values in the closed interval range obtained after splitting, calling the algorithm of the continuous key values in the closed interval range for the type of the key value parameter, and executing the steps S308-S314.
S318: and judging whether to return to a plurality of partitions, if so, executing step S319, and if not, executing step S320.
S319: and performing de-coincidence on the plurality of partitions to obtain a partition set.
S320: a partition set is obtained that contains a partition.
Before step S318, if no suitable partition is matched, returning to the default partition.
The embodiment can realize the vertical and horizontal expansion of distributed caching and pushing, and support various high-performance dynamic routing partition modes of caching information storage, pushing and subscription.
EXAMPLE III
Referring to fig. 6, the present embodiment is a further development of the first embodiment, and the same points are not described again, except that before step S6, the method further includes the following steps:
s8: detecting the running state of each partition main service in the distributed cache partition according to preset monitoring time; the heartbeat detection may be sent to each partition every a predetermined first period (e.g., 10 seconds, which determines the speed of switching after a partition fails to send a fault) to determine the survival status of each partition.
S9: it is determined whether the primary service of a partition fails, and if so, step S10 is executed.
S10: and acquiring ip addresses and port numbers of the master service and the slave service in the partition.
S11: and carrying out hash operation on the instance name of the slave service to obtain a corresponding integer value.
S12: and respectively associating the ip address and the port of the slave service and the integer value corresponding to the slave service to obtain an association relation set.
S13: sorting the incidence relation set according to the integer value; preferably, an ascending sort is performed.
S14: and acquiring a first incidence relation in the incidence relation set.
S15: and judging whether the slave service corresponding to the first association relationship is alive or not, if so, executing the step S16, and if not, executing the step S18.
S16: and closing the connection in the connection pool corresponding to the partition according to the ip address and the port number of the main service.
S17: and according to the ip address and the port number of the slave service, re-acquiring the connection and storing the connection into the corresponding connection pool.
S18: and removing the first incidence relation from the incidence relation set, and executing the step S14.
Preferably, the corresponding ip address and port of each partition and the switching record (whether failover occurs, the original ip and port switched, and the ip and port switched after failover) of each partition may be printed to the log file at intervals of a preset second period (e.g. 30 seconds).
In this embodiment, after the failure of the primary service of the partition is detected, the secondary service is selected to determine a new primary service, so that the disaster recovery of the failure of the partition can be realized. By automatically detecting the fault of each partition, manual configuration is not needed when the node fault is recovered; invalid or aged partition connections can be updated in time, high availability is achieved on the basis of a redundancy mechanism, single-point failure is avoided, automatic discovery of faults is supported, and fault switching is transparently implemented.
Example four
The present embodiment is a specific implementation manner of the foregoing embodiment. In this embodiment, taking the distributed cache redis and three types of application services as examples, the three types of application services are respectively: the method comprises the steps that a user application service, a vehicle application service and an insurance application service are respectively applied in three different partition modes, wherein the user application service adopts a vertical partition type partition based on a name space, the vehicle application service adopts a horizontal partition type partition based on the name space, and the insurance service adopts a read-write separation type partition based on a command variable. The specific implementation steps are as follows:
1. multiple redis cache storage nodes, i.e., partitions, are deployed. The present embodiment deploys 7 redis storage nodes, R1, R21, R22, R31, R32, R41, and R42. Wherein R1 stores the cache data for the user application service; the data of different vehicles are stored by R21 and R31 as a main node (main service) of storage, R22 is a standby node (slave service and slave node) of R21, the data of the two nodes are subjected to master-slave synchronization, R32 is a standby node (slave service and slave node) of R31, the data of the two nodes are subjected to master-slave synchronization, when the node for storing the cache data of the vehicles fails, the corresponding standby node is switched to, and the standby nodes can be deployed in a plurality. The R41 and R42 are used for storing safe cache data, the data of the two nodes are automatically synchronized, but the R41 node is specially used for the operation of writing the cache, and the R42 is specially used for the operation of reading the cache, so that the separation of reading and writing is realized.
2. Service access interface classes are defined separately. The service access interface class needs to inherit an interface base class baseInter provided by the integrated service interface management module in the routing architecture of the first embodiment, the interface base class realizes various common operation methods for cache storage and acquisition, and can basically meet the requirements of most services, each service access interface class can directly call various methods provided by the base class interface, and if the method provided by the existing interface base class cannot meet the requirements of specific services, the method for meeting the specific services can be freely defined and combined by using the basic method of the interface base class. The various characteristics provided by the integrated service interface management module can be obtained by inheriting the service access interface classes of the interface base class. Each service interface class is defined as: a user service interface class UserInter, which is positioned under a namespace org.com.dr.UserInter; a vehicle service interface class, VehicleInterter, located under the namespace org.com.dr.VehicleInterter; an insurance service interface class, instanceel, is located under the namespace org.com.dr.instanceel, and defines the Write and Read command variables under the org.com.dr.instanceel namespace and associates them with corresponding methods.
3. And configuring a partition routing rule. The route partition rule configuration module adds a route partition configuration file under a path appointed by the route partition rule configuration module, and the partition configuration file under the path is loaded by the route partition rule configuration module when the system is started. The route partition configuration rule is configured as follows:
Figure BDA0001071049690000171
4. and configuring parameters of the partition connection pool. The partition connection pool management module is responsible for managing the connection of all partitions, and the connection pools of all partitions adopt uniform configuration. The parameters to be configured are: maximum number of connections, maximum number of idle connections, maximum wait time for connections, maximum idle time for connections, connection detection time interval.
5. And configuring the detection heartbeat frequency and the node health condition printing frequency of the partition fault perception module. The default value of the heartbeat frequency is 10 seconds, and the default value of the printing frequency of the node health state condition is 30 seconds.
6. An application accesses the partition. After the partition routing rule is configured, when the application program is started, the routing partition rule configuration module of the present invention loads the configuration file in step 3 (after the configuration rule occurs, the routing partition rule configuration module performs intelligent sensing and reloads routing configuration information), and when the application program needs to access the partition and read and write the cache data, the application program can directly call each service interface class defined in step 2 to perform partition access. The access request will reach the integrated service interface management module of the invention first, the integrated service interface management will send the request to the route partition analysis module, the route partition rule configuration module will combine the configuration information loaded by the route partition rule configuration module to perform partition routing.
7. And carrying out route matching of a specific partition. And after receiving the request, the route partition analysis module firstly performs partition positioning algorithm matching according to the route key value, and if the request does not have the parameter with the route key value, directly performs partition routing on the naming space and the command variable called by the interface. And returns the matched partition to the integrated service interface management module. For example, according to the rule configured in step 3, the user application service data is totally cached in the R1 partition; the vehicle application service data is divided according to the vehicle id, data with the vehicle id larger than 0 and smaller than or equal to 30000 are cached in the R21, and data with the vehicle id larger than 30000 are cached in the R31 partition. If the vehicle application service does not have the vehicle id when accessing the cached data, accessing a default partition (i.e. a default shards configured partition) R21; the data of the insurance application service is routed in a partitioned mode according to the command variables, the operation on the Write command variable is routed to the R41 partition, and the operation on the Write command variable is routed to the R42 partition.
8. A determination of a partition access policy is made. After obtaining a specific partition, the integrated service interface management module begins to consult the partition access policy module for a policy (a sequential access policy or a concurrent access policy) for accessing the partition, the partition access policy module returns an optimal access policy to the integrated service interface management module, and after receiving the optimal access policy, the integrated service interface management module finally obtains the connection in the connection pool where the corresponding partition is located from the partition connection pool management module according to the access policy.
9. And acquiring partition connection. And 4, loading the parameters of the partition connection pool configured in the step 4 by the partition connection pool management module when the system is started, judging whether idle connection exists or not by the partition connection pool management module when the comprehensive service interface management module acquires connection from the partition connection pool management module, directly returning available connection if the idle connection exists, judging whether the number of connections in the connection pool of the current partition exceeds the configured maximum number of connections if the idle connection does not exist, creating new connection of the current partition if the maximum number of connections does not exceed the configured maximum number of connections, adding the new connection into the connection pool of the current partition, and returning the connection to the connection request object. If the maximum number of connections is exceeded, waiting for the connection being used to be released for the current request, and if no connection is obtained within the configured maximum waiting time, returning to the empty connection. And meanwhile, the partition connection pool management module also detects idle connection.
10. And accessing the partition to perform the operation of caching the data. And after obtaining the partition connection from the partition connection pool management module, the integrated service interface management module formally initiates access to the partitions, performs partition cache data operation, and obtains results returned by each partition. The integrated service interface management module can perform one-time integration on the returned results and return a result set to the application layer.
11. Failover of a partition. And (5) the heartbeat frequency detection and node health state condition printing frequency information of the configured partition fault sensing module in the step 5 is loaded by the partition fault sensing module when the system is started. According to the step 1, data of different vehicles stored by R21 and R31 are used as main nodes for storage, R22 is a standby node of R21, data of the two nodes are subjected to master-slave synchronization, R32 is a standby node of R31, data of the two nodes are subjected to master-slave synchronization, when a node R21 of the vehicle for storing cache data sends a fault, a partition fault sensing module senses the fault and automatically switches to an R22 slave node, meanwhile, the partition connection pool management module is informed to refresh a connection pool corresponding to the original R21, the connection is switched to an R22 partition, and then all operations of accessing the R21 by an application are automatically connected with R22 for access, so that fault switching of the partitions is realized.
EXAMPLE five
Referring to fig. 8, the present embodiment is a distributed cache and push routing system corresponding to the foregoing embodiment, including:
the system comprises a presetting module 1, a service module and a partition module, wherein the presetting module 1 is used for presetting a matching strategy of a request and a partition sent by a requester through a class interface, and the request comprises a service parameter and a partition parameter;
the receiving module 2 is used for receiving a request sent by a requester;
the partition routing module 3 is configured to perform partition routing according to the partition parameter and the matching policy to obtain a partition set including at least one partition;
the generating module 4 is used for generating an access strategy according to the partition set;
a first obtaining module 5, configured to obtain, in a distributed cache partition, a connection corresponding to each partition in the partition set according to the partition set and a corresponding access policy;
the second obtaining module 6 is configured to access the corresponding partition according to the connection, and obtain a corresponding return result;
and the feedback module 7 is used for feeding back the return result to the requesting party.
The preset module 1 includes:
the first association unit 101 is configured to associate the unique identifier of the partition with a namespace of the class interface according to a preset rule to obtain a first association relationship;
the second association unit 102 is configured to associate the unique identifier of the partition, the namespace of the class interface, and the command variable in the class interface according to a preset rule, so as to obtain a second association relationship;
and the third association unit 103 is configured to associate the unique identifier of the partition, the namespace of the class interface, and the routing key value in the partition parameter according to a preset rule, so as to obtain a third association relationship.
The partition routing module 3 includes:
a first determining unit 301, configured to determine whether the partition parameter includes a routing key;
a first returning unit 302, configured to return, if not, the corresponding partition according to the first association relationship or the second association relationship;
a second determining unit 303, configured to determine, if yes, a type of the key value parameter of the routing key value;
a second returning unit 304, configured to return to a preset default partition if the type of the key-value parameter is a null value;
a third returning unit 305, configured to, if the type of the key value parameter is a single key value, perform single value matching according to the third association relationship, and return to the corresponding partition;
a first obtaining unit 306, configured to, if the type of the key value parameter is a continuous key value within a closed interval range, perform single-value matching on the minimum value and the maximum value within the closed interval according to the third correlation, respectively, and obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
a third judging unit 307, configured to judge whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value;
a fourth returning unit 308, configured to return the partition corresponding to the minimum value or the partition corresponding to the maximum value if the two are consistent;
a calculating unit 309, configured to calculate an average of the minimum value and the maximum value if the minimum value and the maximum value are inconsistent;
a rounding unit 310, configured to round the average downwards if the average is not an integer;
a fourth judging unit 311, configured to judge whether the average is equal to a minimum value;
a fifth returning unit 312, configured to return the partition corresponding to the minimum value and the partition corresponding to the maximum value if yes;
a dividing unit 313, configured to divide the closed interval into two closed intervals according to the average number if the closed interval is not the same as the average number;
a first executing unit 314, configured to return to execute the step of performing single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation respectively to obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
the splitting unit 315 is configured to split the multiple hybrid key values to obtain a single key value and continuous key values within a closed interval range if the type of the key value parameter is the multiple hybrid key values;
a second executing unit 316, configured to execute, for a single key value, the step that if the type of the key value parameter is the single key value;
a third executing unit 317, configured to execute the step of determining, for consecutive key values within a closed interval range, if the type of the key value parameter is a consecutive key value within a closed interval range;
a de-overlapping unit 318, configured to, if multiple partitions are returned, perform de-overlapping on the multiple partitions to obtain a partition set.
The generating module 4 comprises:
a sixth returning unit 401, configured to return the sequential access policy if the number of the partitions in the partition set is one;
a fifth determining unit 402, configured to determine whether the service parameter includes a transaction sequence flag variable if the number of the partitions in the partition set is greater than one;
a seventh returning unit 403, configured to return the sequential access policy if yes;
an eighth returning unit 404, configured to return the concurrent access policy if no.
The first obtaining module 5 includes:
a first receiving unit 501, configured to receive a request for acquiring partition connections;
a sixth determining unit 502, configured to determine whether there is an idle connection in the connection pool of the partition;
a ninth returning unit 503, configured to return to an idle connection if there is any;
a seventh determining unit 504, configured to determine whether the number of connections in the connection pool of the partition exceeds a preset maximum number of connections if the number of connections in the connection pool of the partition does not exceed the preset maximum number of connections;
a tenth returning unit 505, configured to create a new connection in the connection pool of the partition if the connection is not exceeded, and return the new connection;
a waiting unit 506, configured to wait for the release of the connection in use if the connection is exceeded;
an eleventh returning unit 507, configured to return to the null connection if the waiting time exceeds a preset maximum waiting time.
Further comprising:
the detection module 8 is used for detecting the running state of the main service of each partition in the distributed cache partition according to the preset monitoring time;
a third obtaining module 9, configured to obtain a slave service in a partition if it is detected that a master service of the partition fails;
and the master selecting module 10 is used for selecting one slave service from the slave services as a new master service according to a master selecting algorithm.
The main selecting module 10 includes:
a second obtaining unit 1001, configured to obtain ip addresses and port numbers of a master service and a slave service in the partition;
an operation unit 1002, configured to perform a hash operation on the instance name of the slave service to obtain a corresponding integer value;
a fourth associating unit 1003, configured to associate an ip address and a port of a slave service and an integer value corresponding to the slave service, respectively, to obtain an association set;
a sorting unit 1004, configured to sort the association set according to the integer value;
a third obtaining unit 1005, configured to obtain a first association relationship in the association relationship set;
an eighth determining unit 1006, configured to determine whether a slave service corresponding to the first association relationship is alive;
a closing unit 1007, configured to close, if yes, a connection in the connection pool corresponding to the partition according to the ip address and the port number of the primary service;
a fourth obtaining unit 1008, configured to obtain a connection again according to the ip address and the port number of the slave service, and store the connection in the corresponding connection pool;
a removing unit 1009, configured to remove the first association relationship from the association relationship set if not;
a fourth executing unit 1010, configured to continue to execute the step of obtaining the first association relationship in the association relationship set.
In summary, the routing method and system for distributed caching and pushing provided by the invention not only realize the vertical and horizontal expansion of distributed caching and pushing, but also support various high-performance dynamic routing partition modes of storage, pushing and subscription of caching information; invalid or aged partition connections can be updated in time, high availability is achieved on the basis of a redundancy mechanism, single-point failure is avoided, automatic discovery of faults is supported, and fault switching is transparently implemented. The whole routing framework provides a single data and management view externally, the interface is simple and easy to use, and manual configuration is not needed when the node failure is recovered, so that the routing framework with high performance, high expansibility, high availability and high usability and capable of realizing distributed caching and pushing is realized.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (6)

1. A routing method for distributed caching and pushing is characterized by comprising the following steps:
presetting a matching strategy of a request and a partition sent by a requester through a class interface, wherein the request comprises a service parameter and a partition parameter;
receiving a request sent by a requester;
according to the partition parameters and the matching strategy, performing partition routing to obtain a partition set comprising at least one partition;
generating an access strategy according to the partition set;
acquiring the connection corresponding to each partition in the partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
accessing the corresponding partition according to the connection to obtain a corresponding return result;
feeding back the return result to the requester;
the "matching policy between the request sent by the preset requester through the class interface and the partition" specifically includes:
associating the unique identifier of the partition with a naming space of the class interface according to a preset rule to obtain a first association relation;
associating the unique identifier of the partition, the name space of the class interface and the command variable in the class interface according to a preset rule to obtain a second association relation;
associating the unique identifier of the partition, the naming space of the class interface and the routing key value in the partition parameter according to a preset rule to obtain a third association relation;
the "performing partition routing according to the partition parameter and the matching policy to obtain a partition set including at least one partition" specifically includes:
judging whether the partition parameters comprise routing key values or not;
if not, returning the corresponding partition according to the first incidence relation or the second incidence relation;
if yes, judging the type of the key value parameter of the routing key value;
if the type of the key value parameter is a null value, returning to a preset default partition;
if the type of the key value parameter is a single key value, performing single value matching according to the third association relation, and returning to the corresponding partition;
if the type of the key value parameter is a continuous key value in a closed interval range, performing single-value matching on the minimum value and the maximum value in the closed interval respectively according to the third correlation, and acquiring a partition corresponding to the minimum value and a partition corresponding to the maximum value;
judging whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value;
if the two are consistent, returning the partition corresponding to the minimum value or the partition corresponding to the maximum value;
if not, calculating the average of the minimum value and the maximum value;
if the average is not an integer, rounding the average downwards;
determining whether the average is equal to a minimum value;
if so, returning the partition corresponding to the minimum value and the partition corresponding to the maximum value;
if not, dividing the closed interval into two closed intervals according to the average number;
respectively returning and executing the step of respectively performing single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation to obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
if the type of the key value parameter is a multi-hybrid key value, splitting the multi-hybrid key value to obtain a single key value and continuous key values in a closed interval range;
for a single key value, executing the step if the type of the key value parameter is the single key value;
for the continuous key values in the closed interval range, executing the step if the type of the key value parameter is the continuous key value in the closed interval range;
and if the plurality of partitions are returned, performing de-coincidence on the plurality of partitions to obtain a partition set.
2. The distributed caching and pushing routing method according to claim 1, wherein the "generating an access policy according to the partition set" is specifically:
if the number of the partitions in the partition set is one, returning a sequential access strategy;
if the number of the partitions in the partition set is more than one, judging whether the service parameters comprise transaction sequence flag variables;
if so, returning the sequential access strategy;
if not, returning the concurrent access strategy.
3. The distributed caching and pushing routing method according to claim 1, wherein the "obtaining connections corresponding to partitions in the partition set in the distributed caching partition" specifically includes:
receiving a request for acquiring partition connection;
judging whether the connection pool of the partition has idle connection;
if yes, returning to the idle connection;
if not, judging whether the connection number in the connection pool of the partition exceeds a preset maximum connection number or not;
if not, creating a new connection in the connection pool of the partition, and returning to the new connection;
if yes, waiting for the connection being used to be released;
and if the waiting time exceeds the preset maximum waiting time, returning to the empty connection.
4. The distributed caching and pushing routing method according to claim 1, wherein before accessing the corresponding partition according to the connection, further comprising:
detecting the running state of each partition main service in the distributed cache partition according to preset monitoring time;
if the main service of a partition is detected to be out of order, acquiring the slave service in the partition;
and selecting one slave service from the slave services as a new master service according to a master selection algorithm.
5. The distributed caching and pushing routing method according to claim 4, wherein the "selecting one of the slave services as a new master service according to a master-select algorithm" is specifically:
acquiring ip addresses and port numbers of the master service and the slave service in the partition;
carrying out hash operation on the instance name of the slave service to obtain a corresponding integer value;
respectively associating an ip address and a port of a slave service and an integer value corresponding to the slave service to obtain an association relation set;
sorting the incidence relation set according to the integer value;
acquiring a first incidence relation in the incidence relation set;
judging whether the slave service corresponding to the first incidence relation is alive or not;
if so, closing the connection in the connection pool corresponding to the partition according to the ip address and the port number of the main service; according to the ip address and the port number of the slave service, connection is obtained again and stored in the corresponding connection pool;
if not, removing the first incidence relation in the incidence relation set; and continuing to execute the step of obtaining the first incidence relation in the incidence relation set.
6. A distributed caching and pushing routing system, comprising:
the system comprises a presetting module, a judging module and a judging module, wherein the presetting module is used for presetting a matching strategy of a request and a partition sent by a requester through a class interface, and the request comprises a service parameter and a partition parameter;
the receiving module is used for receiving a request sent by a requester;
the partition routing module is used for carrying out partition routing according to the partition parameters and the matching strategy to obtain a partition set comprising at least one partition;
the generating module is used for generating an access strategy according to the partition set;
the first acquisition module is used for acquiring the connection of each partition in the corresponding partition set in the distributed cache partition according to the partition set and the corresponding access strategy;
the second acquisition module is used for accessing the corresponding partition according to the connection and acquiring the corresponding return result;
the feedback module is used for feeding back the return result to the requester;
the preset module comprises:
the first association unit is used for associating the unique identifier of the partition with the namespace of the class interface according to a preset rule to obtain a first association relation;
the second association unit is used for associating the unique identifier of the partition, the name space of the class interface and the command variable in the class interface according to a preset rule to obtain a second association relation;
the third association unit is used for associating the unique identifier of the partition, the name space of the class interface and the routing key value in the partition parameter according to a preset rule to obtain a third association relation;
the partition routing module comprises:
the first judging unit is used for judging whether the partition parameters comprise routing key values or not;
the first returning unit is used for returning the corresponding partition according to the first incidence relation or the second incidence relation if the partition is not in the first association relation or the second association relation;
the second judging unit is used for judging the type of the key value parameter of the routing key value if the key value parameter is the same as the type of the key value parameter of the routing key value;
the second returning unit is used for returning to a preset default partition if the type of the key value parameter is a null value;
a third returning unit, configured to, if the type of the key value parameter is a single key value, perform single value matching according to the third association relationship, and return to the corresponding partition;
the first obtaining unit is used for respectively carrying out single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation relationship if the type of the key value parameter is a continuous key value in the closed interval range, and obtaining a partition corresponding to the minimum value and a partition corresponding to the maximum value;
a third judging unit, configured to judge whether the partition corresponding to the minimum value is consistent with the partition corresponding to the maximum value;
the fourth returning unit is used for returning the partition corresponding to the minimum value or the partition corresponding to the maximum value if the two are consistent;
the calculating unit is used for calculating the average of the minimum value and the maximum value if the minimum value and the maximum value are inconsistent;
a rounding unit, configured to round the average downwards if the average is not an integer;
a fourth judging unit configured to judge whether the average is equal to a minimum value;
a fifth returning unit, configured to return, if yes, the partition corresponding to the minimum value and the partition corresponding to the maximum value;
the dividing unit is used for dividing the closed interval into two closed intervals according to the average number if the closed interval is not the same as the average number;
the first execution unit is used for respectively returning and executing the steps of respectively performing single-value matching on the minimum value and the maximum value in the closed interval according to the third correlation to obtain a partition corresponding to the minimum value and a partition corresponding to the maximum value;
the splitting unit is used for splitting the multiple mixed key values to obtain single key values and continuous key values in a closed interval range if the type of the key value parameter is the multiple mixed key values;
a second execution unit, configured to execute, for a single key value, the step that is performed if the type of the key value parameter is the single key value;
a third execution unit, configured to execute, for a continuous key value within a closed interval range, the step that if the type of the key value parameter is the continuous key value within the closed interval range;
and the de-coincidence unit is used for performing de-coincidence on the plurality of partitions to obtain a partition set if the plurality of partitions are returned.
CN201610638721.4A 2016-08-05 2016-08-05 Routing method and system for distributed caching and pushing Active CN107689977B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610638721.4A CN107689977B (en) 2016-08-05 2016-08-05 Routing method and system for distributed caching and pushing

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610638721.4A CN107689977B (en) 2016-08-05 2016-08-05 Routing method and system for distributed caching and pushing

Publications (2)

Publication Number Publication Date
CN107689977A CN107689977A (en) 2018-02-13
CN107689977B true CN107689977B (en) 2021-12-07

Family

ID=61152034

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610638721.4A Active CN107689977B (en) 2016-08-05 2016-08-05 Routing method and system for distributed caching and pushing

Country Status (1)

Country Link
CN (1) CN107689977B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110825794B (en) * 2018-08-14 2022-03-29 华为云计算技术有限公司 Partition merging method and database server
CN109510777B (en) * 2018-11-09 2022-02-22 迈普通信技术股份有限公司 Flow table arranging method and device and SDN controller
CN109903034B (en) * 2019-02-28 2021-06-08 腾讯科技(深圳)有限公司 Rule matching method and device, computer readable storage medium and computer equipment
CN111666278B (en) * 2019-03-06 2024-03-26 阿里巴巴集团控股有限公司 Data storage method, data retrieval method, electronic device and storage medium
CN111913989A (en) * 2020-06-15 2020-11-10 东风日产数据服务有限公司 Distributed application cache refreshing system and method, electronic equipment and storage medium
CN113590699B (en) * 2021-07-14 2023-12-01 车智互联(北京)科技有限公司 Interface request processing method, system and computing device
CN115757584A (en) * 2022-11-29 2023-03-07 广发银行股份有限公司 System access method based on query interface

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102244685A (en) * 2011-08-11 2011-11-16 中国科学院软件研究所 Distributed type dynamic cache expanding method and system supporting load balancing
CN105187503A (en) * 2015-08-07 2015-12-23 北京思特奇信息技术股份有限公司 Data partition supporting service connection method and system
CN105630419A (en) * 2015-12-25 2016-06-01 华为技术有限公司 Partition view sending method of resource pools and management node
CN105677761A (en) * 2015-12-30 2016-06-15 国网信息通信产业集团有限公司 Data sharding method and system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2003239385A1 (en) * 2002-05-10 2003-11-11 Richard R. Reisman Method and apparatus for browsing using multiple coordinated device
US9860316B2 (en) * 2014-09-19 2018-01-02 Facebook, Inc. Routing network traffic based on social information

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102244685A (en) * 2011-08-11 2011-11-16 中国科学院软件研究所 Distributed type dynamic cache expanding method and system supporting load balancing
CN105187503A (en) * 2015-08-07 2015-12-23 北京思特奇信息技术股份有限公司 Data partition supporting service connection method and system
CN105630419A (en) * 2015-12-25 2016-06-01 华为技术有限公司 Partition view sending method of resource pools and management node
CN105677761A (en) * 2015-12-30 2016-06-15 国网信息通信产业集团有限公司 Data sharding method and system

Also Published As

Publication number Publication date
CN107689977A (en) 2018-02-13

Similar Documents

Publication Publication Date Title
CN107689977B (en) Routing method and system for distributed caching and pushing
US8954391B2 (en) System and method for supporting transient partition consistency in a distributed data grid
US20200257593A1 (en) Storage cluster configuration change method, storage cluster, and computer system
US10599677B2 (en) Methods and systems of splitting database indexes and digests
US9201742B2 (en) Method and system of self-managing nodes of a distributed database cluster with a consensus algorithm
US11218418B2 (en) Scalable leadership election in a multi-processing computing environment
US8676951B2 (en) Traffic reduction method for distributed key-value store
US11093468B1 (en) Advanced metadata management
US20160085829A1 (en) Query method for a distributed database system and query apparatus
JP2019518260A (en) Method, apparatus, computer program product, data center facility for multi-tenant memory service for memory pool architecture
US20160078117A1 (en) Policy-based Storage Structure Distribution
CN111858097A (en) Distributed database system and database access method
WO2011137189A1 (en) System and methods for mapping and searching objects in multidimensional space
EP1716505A2 (en) Ultra-shared-nothing parallel database
US20150169718A1 (en) System and method for supporting persistence partition discovery in a distributed data grid
US11609914B2 (en) Policy-based storage structure distribution
AU2015408848A1 (en) Method for processing acquire lock request and server
CN107832159A (en) Manage the method and computer-readable recording medium of distributed lock
CN112162707A (en) Storage method, electronic device and storage medium for distributed storage system
CN113704361B (en) Transaction execution method and device, computing equipment and storage medium
CN111597270A (en) Data synchronization method, device, equipment and computer storage medium
US9703788B1 (en) Distributed metadata in a high performance computing environment
CN107180034A (en) The group system of MySQL database
CN105868210A (en) Creating method and device of unique index in distributed database
KR20130038517A (en) System and method for managing data using distributed containers

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant