CN115481103A - Database capacity expansion and reduction method and device and computer readable storage medium - Google Patents

Database capacity expansion and reduction method and device and computer readable storage medium Download PDF

Info

Publication number
CN115481103A
CN115481103A CN202211033983.XA CN202211033983A CN115481103A CN 115481103 A CN115481103 A CN 115481103A CN 202211033983 A CN202211033983 A CN 202211033983A CN 115481103 A CN115481103 A CN 115481103A
Authority
CN
China
Prior art keywords
data
database
node
relocation
original
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.)
Pending
Application number
CN202211033983.XA
Other languages
Chinese (zh)
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.)
China Unionpay Co Ltd
Original Assignee
China Unionpay 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 China Unionpay Co Ltd filed Critical China Unionpay Co Ltd
Priority to CN202211033983.XA priority Critical patent/CN115481103A/en
Publication of CN115481103A publication Critical patent/CN115481103A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method and a device for expanding and reducing the volume of a database and a computer readable storage medium, wherein the method comprises the following steps: setting a database dividing field of a database table in an SQL statement, uniformly dividing data into a set number of data slots according to the database dividing field, and calculating an original database dividing result corresponding to the data slots; under the condition that the database cluster is subjected to capacity expansion and contraction, calculating an updated sub-database result corresponding to the data slot according to the number of updated nodes; determining the relocation route direction of the data slot according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot. By using the method, the data expansion and contraction can be implemented on line, the application halt is not needed, the application transaction is not influenced, and the operation and maintenance implementation steps are simplified.

Description

Database capacity expansion and contraction method and device and computer readable storage medium
Technical Field
The invention belongs to the field of databases, and particularly relates to a database capacity expansion and reduction method, a database capacity expansion and reduction device and a computer readable storage medium.
Background
This section is intended to provide a background or context to the embodiments of the invention that are recited in the claims. The description herein is not admitted to be prior art by inclusion in this section.
The problem of expansion and contraction of a distributed database is long-standing, and most of the prior processing methods are to newly build a database cluster, stop the original cluster service, and switch the service to a new cluster after data relocation.
The method has great influence on the application, and not only needs to interrupt the service, but also needs to consume a great deal of time and energy to carry out the work of data relocation, service switching and the like. Therefore, a method for expanding and reducing the size of a transparent and non-sensitive image, which is friendly to the application operation, is very urgent and important.
Disclosure of Invention
In view of the problems in the prior art, a method, an apparatus and a computer-readable storage medium for expanding and contracting a database are provided.
The present invention provides the following.
In a first aspect, a method for scaling a database is provided, where the database includes one or more agents and a plurality of data nodes connected to the agents, and the method includes: setting a database dividing field of a database table in an SQL statement, uniformly dividing data into a set number of data slots according to the database dividing field, and calculating an original database dividing result corresponding to the data slots; under the condition that the database cluster is subjected to capacity expansion and contraction, calculating an updated sub-database result corresponding to the data slot according to the number of updated nodes; determining the relocation route direction of the data slot according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot.
In one embodiment, before data relocation of a data slot, node routing is performed by using an original database partitioning rule; in the process of carrying out data relocation on the data slot, carrying out node routing by using an original database partitioning rule and a coexistence rule of an updated database partitioning rule; and after the data relocation of the data slot is finished, node routing is carried out by adopting the updating branch base rule.
In one embodiment, during the data relocation, the method further includes: for Insert statements, node routing is done using updated sublibrary rules.
In one embodiment, during the data relocation, the method further includes: aiming at an Update (Update) statement or a Select (Select) statement or a Delete (Delete) statement, an original library partitioning rule and an Update library partitioning rule are respectively used for calculating two library partitioning results, statements are executed on an original node and an Update node corresponding to the two library partitioning results, and response results of the statements executed on the original node and the Update node are combined by an agent.
In one embodiment, the data migration includes one or more migration tasks, each migration task for migrating one or more data slots, the migration tasks including: connecting the agents and opening the session, setting the transaction isolation level of the session to read-committed (read-committed) and setting the session to auto-commit; starting a transaction, reading a data slot to be moved from an original node, and inserting the data slot into an update node through an agent according to an update sub-base rule; if the situation that the primary key is repeated exists in the newly added data slot inserted into the update node, deleting the data slot of the update node and executing reinsertion; if the newly added data slot inserted into the update node is normal, deleting the data slot to be moved of the original node: the transaction either commits successfully or rolls back in failure.
In one embodiment, the relocation task includes: and when the data slot to be moved is read from the original node, locking the data slot to be moved by using the read-write lock grammar.
In one embodiment, the method comprises the following steps: the number of data slots is increased.
In one embodiment, the method further comprises: calculating the hash value of the sub-library field by the agent, and performing modulo operation on the number of the data slots according to the hash value of the sub-library field to obtain the number of each data slot; and performing modulus extraction on the number of the data nodes according to the number of the data slots to obtain the routing data node corresponding to each data slot.
In a second aspect, an apparatus for expanding and reducing a database is provided, the apparatus comprising: the original database partitioning module is used for setting database partitioning fields of a database table in an SQL sentence, uniformly partitioning data into a set number of data slots according to the database partitioning fields and calculating original database partitioning results corresponding to the data slots; the updating and database partitioning module is used for calculating an updating and database partitioning result corresponding to the data slot according to the number of the updated nodes under the condition that the database cluster generates the expansion and contraction capacity; the data relocation module is used for determining the relocation routing direction of the data slot according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot.
In a third aspect, an apparatus for scaling a database is provided, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to cause the at least one processor to perform: the method of the first aspect.
In a fourth aspect, there is provided a computer readable storage medium storing a program which, when executed by a multicore processor, causes the multicore processor to perform the method of the first aspect.
One of the advantages of the above embodiment is that an implementation method capable of expanding and contracting capacity in situ is provided, and the implementation method can be implemented online, does not need application shutdown, does not affect application transaction, and simplifies operation and maintenance implementation steps.
Other advantages of the present invention will be explained in more detail in conjunction with the following description and the accompanying drawings.
It should be understood that the above description is only an overview of the technical solutions of the present invention, so that the technical means of the present invention can be more clearly understood and implemented according to the content of the specification. In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below.
Drawings
The advantages and benefits, and other advantages and benefits, herein will become apparent to those of ordinary skill in the art upon reading the following detailed description of the exemplary embodiments. The drawings are only for purposes of illustrating exemplary embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like elements throughout. In the drawings:
FIG. 1 is a schematic structural diagram of a database capacity expansion device according to an embodiment of the present invention
FIG. 2 is a flowchart illustrating a database capacity expansion and reduction method according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a database structure according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a database scaling device according to another embodiment of the present invention.
In the drawings, the same or corresponding reference numerals indicate the same or corresponding parts.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
In the description of the embodiments of the present application, it is to be understood that terms such as "including" or "having" are intended to indicate the presence of the features, numbers, steps, actions, components, parts, or combinations thereof disclosed in the specification, and are not intended to preclude the presence or addition of one or more other features, numbers, steps, actions, components, parts, or combinations thereof.
A "/" indicates an OR meaning, for example, A/B may indicate A or B; "and/or" herein is merely an association relationship describing an associated object, and means that there may be three relationships, for example, a and/or B, and may mean: a exists alone, A and B exist simultaneously, and B exists alone.
The terms "first", "second", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first," "second," etc. may explicitly or implicitly include one or more of that feature. In the description of the embodiments of the present application, "a plurality" means two or more unless otherwise specified.
All code in this application is exemplary and variations will occur to those skilled in the art depending on the programming language used, the specific needs and personal preferences, etc., without departing from the spirit of the application.
Referring initially to FIG. 1, a schematic diagram of an environment 100 is schematically illustrated in which exemplary implementations according to the present disclosure may be used.
Fig. 1 shows a schematic diagram of an example of a computing device 100, according to an embodiment of the present disclosure. It should be noted that fig. 1 is a schematic structural diagram of a hardware operating environment of the database capacity expansion and reduction method. The database-based expansion and reduction device of the embodiment of the invention can be a terminal device such as a PC, a portable computer and the like.
As shown in fig. 1, the database scaling device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. The communication bus 1002 is used to implement connection communication among these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory such as a disk memory. The memory 1005 may alternatively be a storage device separate from the processor 1001 described previously.
Those skilled in the art will appreciate that the database scale device configuration shown in fig. 1 does not constitute a limitation of the database scale device and may include more or fewer components than those shown, or some components in combination, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a database scale program. The operating system is a program for managing and controlling hardware and software resources of the database scaling device and supports the operation of the database scaling program and other software or programs.
In the database capacity expansion device shown in fig. 1, the user interface 1003 is mainly used for receiving requests, data and the like sent by the first terminal, the second terminal and the supervision terminal; the network interface 1004 is mainly used for connecting the background server and performing data communication with the background server; and the processor 1001 may be configured to call the database scaling program stored in the memory 1005 and perform the following operations:
setting a database dividing field of a database table in an SQL statement, uniformly dividing data into a set number of data slots (slots) according to the database dividing field, and calculating an original database dividing result corresponding to the data slots (slots); under the condition that the database cluster is subjected to expansion and contraction capacity, calculating an updated sub-database result corresponding to a data slot (slot) according to the number of updated nodes; determining the moving route direction of a data slot (slot) according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot (slot).
Therefore, the database can be expanded and contracted without application halt or influence on application transaction, and operation and maintenance implementation steps are simplified.
FIG. 2 shows a flow chart for performing a database scale-up and scale-down method according to an embodiment of the present disclosure. The method may be performed, for example, by a computing device 100 as shown in FIG. 1. It should be understood that method 200 may also include additional blocks not shown and/or may omit blocks shown, as the scope of the disclosure is not limited in this respect.
Step 210, setting a database dividing field of a database table in an SQL statement, uniformly dividing data into a set number of data slots (slots) according to the database dividing field, and calculating an original database dividing result corresponding to the data slots (slots); the original database partitioning result is also the result of partitioning the data slot (slot) according to the original database partitioning rule.
Step 220, under the condition that the database cluster is subjected to capacity expansion and contraction, calculating an updated sub-database result corresponding to a slot according to the number of updated nodes; the updated database partitioning result is also the result of partitioning the data slot (slot) according to the updated database partitioning rule.
Step 230, determining the relocation route direction of the slot according to the original database partitioning result and the updated database partitioning result;
and 240, carrying out data relocation from the original node to the updated node according to the relocation routing direction of the slot.
Referring to fig. 3, a database includes one or more agents and a plurality of data nodes connected to the agents, and the following describes an embodiment of the present application in detail with reference to fig. 3 and a specific example. For example, 1) when a data node needs to be expanded from 2 nodes to 4 nodes. 2) Under the original library partitioning rule: 1024 slots are routed alternately to node 1 and node 2, as: the slot with the number 0 is routed to the node 1, the slot with the number 1 is routed to the node 2, the slot with the number 2 is routed to the node 1, the slot with the number 3 is routed to the node 2, and so on. 3) Updating the sub-library rules: the 1024 slots are routed alternately to node 1, node 2, node 3 and node 4, as: the slot numbered 0 is routed to node 1, the slot numbered 1 is routed to node 2, the slot numbered 2 is routed to node 3, the slot numbered 3 is routed to node 4, and so on. 4) Relocation routing: it can be seen that the slot routing rules numbered 0 and 1 are unchanged, the slots numbered 2 and 3 need to be moved, slot 2 is moved from node 1 to node 3, and slot 3 is moved from node 2 to node 4. Therefore, in this scenario, approximately half of all 1024 slots need to be relocated.
Slot Old database rule (2 pieces) New library rule (4 pieces) Direction of data relocation
0 DN 1 DN 1 Is free of
1 DN 2 DN 2 Is free of
2 DN 1 DN 3 DN1->DN3
3 DN 2 DN 4 DN2->DN4
4 DN 1 DN 1 Is free of
…… …… …… ……
1023 DN 2 DN 4 DN2->DN4
In one embodiment, in step 210, a hash value of the sub-pool field may be calculated by the agent, and the number of the data slots (slots) is modulo according to the hash value of the sub-pool field to obtain the number of each data slot (slot); and step 220, under the condition that the database cluster is subjected to expansion and contraction capacity, calculating an updated sub-database result corresponding to the data slot (slot) according to the number of the updated nodes.
In one embodiment, in step 210 or step 220, the number of data nodes may be modulo according to the number of the data slot (slot) to obtain the data node to which each data slot (slot) should be routed.
In one embodiment, in order to maintain the database running correctly before, during and after data relocation, the original database partitioning rule can be used for node routing before data relocation in a data slot (slot); in the process of carrying out data relocation in a data slot (slot), carrying out node routing by using an original database partitioning rule and a coexistence rule for updating the database partitioning rule; and after the data relocation of the data slot (slot) is finished, node routing is performed by adopting an updated sub-base rule.
In an embodiment, new and old rules coexist during the relocation process until the relocation is finished, and in order to ensure the correctness of the execution result of the SQL statement when two types of banking rules coexist, adaptation modification may be performed on the statement route, which specifically includes: in the process of data relocation, node routing is carried out by using an update sublibrary rule aiming at an Insert (Insert) statement. Namely, all the newly added data are written according to the updating branch library rule.
In an embodiment, in the process of data relocation, for an Update (Update) statement or a Select (Select) statement or a Delete (Delete) statement, two types of library partitioning results are calculated by using an original library partitioning rule and an updated library partitioning rule respectively, the statements are executed on both an original node and an updated node corresponding to the two types of library partitioning results, and response results of the statements executed by the original node and the updated node are combined by the agent.
For example, if a certain update statement (update xx set a = 1work board keyboard key = xxx) calculates that the node 1 needs to be executed according to the original library partitioning rule, and calculates that the node 3 needs to be executed according to the updated library partitioning rule, the agent finds the union of the two rules and makes an execution plan for executing both the nodes 1 and 3. If the data to be updated is not migrated yet and is still stored in the node 1, the update of the node 1 is successfully executed, and a row of data is hit. Meanwhile, the update of the node 3 is successfully executed, but the data is not hit, the agent combines the response results of the two and returns to the application, and the 1 st row of data is hit.
Therefore, the SQL sentences can be guaranteed to be accurate in execution result when new and old database partitioning rules coexist in the relocation process.
In one embodiment, the data migration includes one or more migration tasks, each migration task for migrating one or more data slots (slots), the migration tasks including:
(1) Connecting the proxy and opening a session;
(2) Setting a transaction isolation level of the session to read-committed;
(3) Setting the session to auto-commit (set autocommit = 1);
(4) Starting a transaction;
(5) Reading a data slot (slot) to be moved from an original node; for example, the following sentence may be employed:
datanode = xxx/select from xx where 'slot id' IN (xx) LOCK IN shield MODE; the/Annotation syntax may specify the name of the data node
(6) Inserting a data slot (slot) into an update node according to an update sub-base rule through an agent; for example, the following sentence may be employed: INSERT intoxx (col 1, col 2.) values (xx, xx);
(7) Optionally, if the new data slot (slot) inserted into the update node has a condition that the primary key is repeated, deleting the data slot (slot) of the update node and performing reinsertion; for example, the following sentence may be employed:
/*+DRDB:datanode=xxx*/DELETE FROM xx WHERE…
INSERT INTO xx(col1,col2..)values(xx,xx);
the steps are used for solving the problem that after the newly added data are inserted into the update node according to the update branch base rule, the newly added data substantially conflict with the old data which are not moved. The data can be compensated and corrected through the steps, newly-added data with conflict of the main key is deleted, and old data are reserved.
(8) Optionally, if the newly added data slot (slot) inserted into the update node is normal, deleting the data slot (slot) to be migrated of the original node: for example, the following sentence may be employed:
/*+DRDB:datanode=xxx*/DELETE FROM xx WHERE…
(9) The transaction either commits successfully or rolls back in failure.
In an embodiment, in order to ensure that the execution result of the SQL statement of the application is not affected by the relocation, when the data slot (slot) to be relocated is read from the original node, the data slot (slot) to be relocated is locked by using the read-write lock syntax. Specifically, in the above relocation task, when the original node reads data in a data slot (slot), the original node locks the part of data to be relocated by using a lock in share mode, so that the other sessions stop responding when performing modification and deletion (update, delete) of the data, thereby ensuring data consistency.
In one embodiment, to minimize the effects of locking, the number of data slots (slots) may be increased so that less data is locked per time.
By adopting the embodiment of the application, the convenience of the capacity expansion and contraction can be obviously improved, a user only needs to select the number of nodes to be increased or decreased on a cloud pipe platform (such as a DBaaS (digital broadcast service) and a public cloud platform), and the platform can start to execute the capacity expansion and contraction step without operation and maintenance or intervention of application developers. And during the expansion and contraction of the volume, the normal transaction of the application does not need to be interrupted, and the execution correctness of the SQL statement is not influenced. In addition, the capacity expansion and reduction mode is in-situ upgrading, and no additional cluster is needed to be built. The scheme supports timing and segmented expansion and contraction capacity, data relocation can be carried out for a system with a large data volume for multiple times, execution time is specified, and the peak period of transaction is avoided.
It should be noted that, for steps that are not described in detail in this embodiment, reference may be made to descriptions in related steps in the embodiment shown in fig. 1, and details are not described here again.
In the description of the present specification, reference to the description of the terms "some possible embodiments," "some embodiments," "examples," "specific examples," or "some examples," or the like, means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, the various embodiments or examples and features of the various embodiments or examples described in this specification can be combined and combined by those skilled in the art without contradiction.
With regard to the method flow diagrams of embodiments of the present application, certain operations are described as different steps performed in a certain order. Such flow diagrams are illustrative and not restrictive. Certain steps described herein may be grouped together and performed in a single operation, may be divided into multiple sub-steps, and may be performed in an order different than that shown herein. The various steps shown in the flowcharts can be implemented in any manner by any circuit structure and/or tangible mechanism (e.g., by software running on a computer device, hardware (e.g., a logical function implemented by a processor or chip), etc., and/or any combination thereof).
Based on the same technical concept, the embodiment of the present invention further provides a database capacity expansion and reduction device, which is used for executing the database capacity expansion and reduction method provided by any of the above embodiments. Fig. 4 is a schematic structural diagram of a database scale and scale device according to an embodiment of the present invention.
As shown in fig. 4, the apparatus 4 includes:
the original database partitioning module 410 is used for setting database partitioning fields of a database table in an SQL statement, uniformly partitioning data into a set number of data slots (slots) according to the database partitioning fields, and calculating original database partitioning results corresponding to the data slots (slots);
an update sub-library module 420, configured to calculate, according to the number of updated nodes, an update sub-library result corresponding to a data slot (slot) when the database cluster is subjected to capacity expansion and contraction;
the data relocation module 430 is configured to determine a relocation routing direction of a data slot (slot) according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot (slot).
It should be noted that the apparatus in the embodiment of the present application may implement each process of the foregoing method embodiment, and achieve the same effect and function, which are not described herein again.
According to some embodiments of the present application, there is provided a non-transitory computer storage medium of a database scale-up and scale-down method having stored thereon computer-executable instructions configured to, when executed by a processor, perform: the method of the above embodiment.
The embodiments in the present application are described in a progressive manner, and the same and similar parts among the embodiments can be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for apparatus, device, and computer-readable storage medium embodiments, the description of which is simplified since it is substantially similar to the method embodiments, and where relevant, reference may be made to some descriptions of the method embodiments.
The apparatus, the device, and the computer-readable storage medium provided in the embodiments of the present application correspond to the method one to one, and therefore, the apparatus, the device, and the computer-readable storage medium also have similar advantageous technical effects to the corresponding method.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, apparatus (device or system), or computer-readable storage medium. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the invention may take the form of a computer-readable storage medium on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The present invention has been described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (devices or systems), and computer-readable storage media according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Disks (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Moreover, while the operations of the method of the invention are depicted in the drawings in a particular order, this does not require or imply that the operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
While the spirit and principles of the invention have been described with reference to several particular embodiments, it is to be understood that the invention is not limited to the disclosed embodiments, nor is the division of aspects, which is for convenience only as the features in such aspects may not be combined to benefit. The invention is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims (11)

1. A method for scaling a database, wherein the database comprises one or more agents and a plurality of data nodes connected to the agents, the method comprising:
setting a database dividing field of a database table in an SQL statement, uniformly dividing data into a set number of data slots according to the database dividing field, and calculating an original database dividing result corresponding to the data slots;
under the condition that the database cluster is subjected to capacity expansion and contraction, calculating an updated sub-database result corresponding to the data slot according to the number of updated nodes;
determining the relocation route direction of the data slot according to the original database partitioning result and the updated database partitioning result;
and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot.
2. The method of claim 1,
before the data relocation of the data slot, node routing is carried out by using an original database partitioning rule;
in the process of carrying out data relocation on the data slot, carrying out node routing by using an original database partitioning rule and a coexistence rule for updating the database partitioning rule;
and after the data relocation of the data slot is finished, the node routing is carried out by adopting the updating branch base rule.
3. The method of claim 1, wherein during the data relocation, further comprising:
and for an Insert (Insert) statement, performing node routing by using the updated sub-library rule.
4. The method according to claim 1, wherein during the data relocation process, further comprising:
and aiming at an Update (Update) statement or a Select (Select) statement or a Delete (Delete) statement, respectively using the original library partitioning rule and the Update library partitioning rule to calculate two library partitioning results, executing the statements at the original node and the Update node corresponding to the two library partitioning results, and combining the response results of the original node and the Update node execution statements by an agent.
5. The method of claim 1, wherein the data migration includes one or more migration tasks, each migration task for migrating one or more data slots, the migration tasks including:
connecting agents and opening a session, setting a transaction isolation level of the session to read-committed (read-committed), and setting the session to auto-commit;
starting a transaction, reading the data slot to be moved from the original node, and inserting the data slot into the update node through an agent according to an update sub-base rule;
if the situation that the primary key is repeated exists in the newly added data slot inserted into the updating node, deleting the data slot of the updating node and executing reinsertion;
if the newly added data slot inserted into the update node is normal, deleting the data slot to be migrated of the original node:
the transaction either commits successfully or rolls back in failure.
6. The method of claim 1, wherein the relocation task comprises:
and when the data slot to be moved is read from the original node, locking the data slot to be moved by using a read-write lock grammar.
7. The method of claim 1, comprising:
and increasing the number of the data slots.
8. The method of claim 1, further comprising:
the agent calculates the Hash value of the database dividing field, and performs modulus operation on the number of the data slots according to the Hash value of the database dividing field to obtain the number of each data slot; and (c) a second step of,
and performing modulus extraction on the number of the data nodes according to the number of the data slot to obtain a routing data node corresponding to each data slot.
9. An apparatus for scaling a database, the apparatus comprising:
the original database partitioning module is used for setting database partitioning fields of a database table in an SQL sentence, uniformly partitioning data into a set number of data slots according to the database partitioning fields and calculating original database partitioning results corresponding to the data slots;
the updating and database dividing module is used for calculating an updating and database dividing result corresponding to the data slot according to the number of the updated nodes under the condition that the database cluster generates the expansion and contraction capacity;
the data relocation module is used for determining the relocation routing direction of the data slot according to the original database partitioning result and the updated database partitioning result; and carrying out data relocation from the original node to the updated node according to the relocation routing direction of the data slot.
10. A database scaling device, comprising:
at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to cause the at least one processor to perform: the method of any one of claims 1-8.
11. A computer-readable storage medium storing a program that, when executed by a multi-core processor, causes the multi-core processor to perform the method of any one of claims 1-8.
CN202211033983.XA 2022-08-26 2022-08-26 Database capacity expansion and reduction method and device and computer readable storage medium Pending CN115481103A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211033983.XA CN115481103A (en) 2022-08-26 2022-08-26 Database capacity expansion and reduction method and device and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211033983.XA CN115481103A (en) 2022-08-26 2022-08-26 Database capacity expansion and reduction method and device and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN115481103A true CN115481103A (en) 2022-12-16

Family

ID=84423035

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211033983.XA Pending CN115481103A (en) 2022-08-26 2022-08-26 Database capacity expansion and reduction method and device and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN115481103A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116701410A (en) * 2023-08-07 2023-09-05 北京大学 Method and system for storing memory state data for data language and digital networking system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116701410A (en) * 2023-08-07 2023-09-05 北京大学 Method and system for storing memory state data for data language and digital networking system
CN116701410B (en) * 2023-08-07 2023-11-14 北京大学 Method and system for storing memory state data for data language of digital networking

Similar Documents

Publication Publication Date Title
KR102341388B1 (en) Method, apparatus, device and storage medium for upgrading application
US6526441B2 (en) Input/output device information management system for multi-computer system
US8738624B1 (en) Increasing distributed database capacity
US20190340171A1 (en) Data Redistribution Method and Apparatus, and Database Cluster
WO2017050064A1 (en) Memory management method and device for shared memory database
CN105550306A (en) Multi-copy data reading/writing method and system
US20240160528A1 (en) Data Storage Method and Apparatus in Storage System
US11726743B2 (en) Merging multiple sorted lists in a distributed computing system
CN111400256B (en) Method and device for calling resource file by application program
CN115481103A (en) Database capacity expansion and reduction method and device and computer readable storage medium
US20200242104A1 (en) Method and system for data handling
CN111090701B (en) Service request processing method, device, readable storage medium and computer equipment
CN115982101B (en) Machine room data migration method and device based on multi-machine room copy placement strategy
CN113127430B (en) Mirror image information processing method, mirror image information processing device, computer readable medium and electronic equipment
CN110895545A (en) Shared data synchronization method and device
JP2006251990A (en) Database reorganization program and database reorganization method
CN107357691B (en) Method and device for processing mirror image file
US20200242132A1 (en) Method and system for data handling
CN113901057A (en) Data playback method and device, computer equipment and storage medium
CN111782634B (en) Data distributed storage method, device, electronic equipment and storage medium
CN112612503A (en) Internationalized resource expansion method and device for software
JP2016062311A (en) Update device and information processing method
CN110096389A (en) A kind of starting method, apparatus, equipment and the storage medium of database
US20050044090A1 (en) Computer system and program
WO2017076180A1 (en) Virtual machine upgrading method and device

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