CN109241177A - A kind of database key generation method suitable for distributed system - Google Patents

A kind of database key generation method suitable for distributed system Download PDF

Info

Publication number
CN109241177A
CN109241177A CN201810763653.3A CN201810763653A CN109241177A CN 109241177 A CN109241177 A CN 109241177A CN 201810763653 A CN201810763653 A CN 201810763653A CN 109241177 A CN109241177 A CN 109241177A
Authority
CN
China
Prior art keywords
distributed system
timestamp
database
serial number
major key
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
CN201810763653.3A
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.)
Sichuan University
Original Assignee
Sichuan University
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 Sichuan University filed Critical Sichuan University
Priority to CN201810763653.3A priority Critical patent/CN109241177A/en
Publication of CN109241177A publication Critical patent/CN109241177A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present invention provides a kind of database key generation methods suitable for distributed system, belong to computer application technology, solve the problems, such as the conflict of traditional distributed system major key.Since traditional distributed system possesses multiple terminals, when each independent terminal transaction operation, may operating database simultaneously, the problem of being also easy to produce database key conflict.In order to solve this problem, mechanism is added timestamp using serial number to avoid major key conflict.Specifically: when the terminal of distributed system needs to be inserted into data to database, current timestamp is firstly generated, the serial number then generated with program is spliced, and the major key of database is eventually formed.Since the uniqueness of serial number can ensure that the major key of insertion database is also unique.The present invention can be with effective solution major key collision problem as caused by distributed system transaction operation, it is ensured that the uniqueness of major key in database.It is simple and efficient compared with the existing methods.

Description

A kind of database key generation method suitable for distributed system
Technical field
The present invention relates to computer application technology, especially a kind of database key suitable for distributed system is raw At method.
Background technique
In Distributed system design, when the multiple terminals of distributed system carry out simultaneously newly-increased operation data item it is more when, Data item operation major key conflict can be generated, the uniqueness of database key is broken at this time, causes the barrier of the subsequent operations such as inquiry Hinder.
The database key generation method of mainstream is predominantly from increasing strategy and UUID primary key generation strategies at present.It is tactful from increasing The major key of integer type is incrementally generated, but this method is not suitable for distributed system.UUID primary key generation strategies The global uniqueness for each data item major key that the newly-increased operation of data item generates can be effectively ensured, but UUID is mostly 32 words String type is accorded with, committed memory is larger and Query Efficiency is low.
Present invention combination requirement in practical systems, provides a kind of serial number and adds timestamp the database key of mechanism and generate plan Slightly, it is ensured that the global uniqueness of generated major key under distributed environment, and major key is integer type, is effectively increased Query Efficiency.
Summary of the invention
The present invention provides a kind of database key generation methods suitable for distributed system, can be effectively solved biography The major key collision problem for distributed system of uniting.
To solve the above-mentioned problems, technical solution of the invention are as follows: the database of mechanism is added timestamp based on serial number Primary key generation strategies, which is characterized in that mainly include the following steps:
(1) when each independent terminal log of distributed system carries out insertion operation according to library, current timestamp is generated;
(2) in order to avoid major key conflict, this serial number operated is generated by program;
(3) splice timestamp and serial number generates new character string;
(4) String data type generated is converted to long, the major key as current operation.
Compared with prior art, the advantage of the embodiment of the present invention are as follows: database key generation method provided by the invention has Effect solves the problems, such as that distributed system data item increases operation hour newly and repeats according to library major key, and the database key generates Operation major key produced by method can effectively improve Query Efficiency.
Detailed description of the invention
Fig. 1: for overall flow schematic diagram of the invention;
Fig. 2: for serial number gencration algorithm flow schematic diagram of the invention.
Specific embodiment
In order to be clearer and more clear the elaboration of the purpose of the embodiment of the present invention, technical solution and advantage and unambiguously, with Lower combination accompanying drawings and embodiments, are described in further detail the embodiment of the present invention.It should be appreciated that described herein specific The examples are only for explaining the invention, is not intended to limit the present invention.
As shown in Figure 1, the present invention is a kind of database key generation method suitable for distributed system, feature exists In mainly including the following steps:
(1) when each independent terminal log of distributed system carries out insertion operation according to library, current timestamp is generated;
(2) in order to avoid major key conflict, this serial number operated is generated by program;
(3) splice timestamp and serial number generates new character string;
(4) String data type generated is converted to long, the major key as current operation.
1. generating current time stamp
The timestamp generation method returns to current time as current time using Calendar abstract class in Java library Stab numerical value.
As a preferred embodiment of the present invention, the current time stamp generation method, the current time stamp of generation Numerical value is the signless long data type being accurate to as unit of millisecond, can reduce to greatest extent and duplicate timestamp numerical value Probability.
2. the customized serial number of Program Generating
Fig. 2 shows serial number gencration algorithm flow provided in an embodiment of the present invention, specifically: in counter Counter is stored in In depositing, to save the sequence number value of the newly-increased operation of current data item.Sequence number value count range is [0,99].
As a preferred embodiment of the present invention, the counter Counter is as global variable, data type setting Calculating speed is improved for Byte type to reduce EMS memory occupation.
3. splicing the major key of timestamp and serial number gencration current operation
Fig. 1 shows the timestamp numerical value of generation and serial number carries out the algorithm flow that splicing generates current operation major key, specifically: The timestamp numerical value of generation splices serial number after moving to left two, serial number is as suffix, to eliminate repetition major key.
As a preferred embodiment of the present invention, the String data type of generation is converted to long, as current The major key of operation, to improve Query Efficiency.

Claims (5)

1. a kind of database key generation method suitable for distributed system, which comprises the steps of:
(1) when each independent terminal log of distributed system carries out insertion operation according to library, current timestamp is generated;
(2) in order to avoid major key conflict, this serial number operated is generated by program;
(3) splice timestamp and serial number generates new character string;
(4) String data type generated is converted to long, the major key as current operation.
2. a kind of database key generation method suitable for distributed system according to claim 1, which is characterized in that Timestamp generation method in the step (1) is returned to current time and is used as and worked as using Calendar abstract class in Java library Preceding timestamp numerical value.
3. current time stamp generation method according to claim 2, the current time stamp numerical value of generation is to be accurate to milli Second is the signless long data type of unit, can reduce the probability for duplicating timestamp numerical value to greatest extent.
4. a kind of database key generation method suitable for distributed system according to claim 1, which is characterized in that In the step (2), when considering only with timestamp mechanism, when the end for carrying out the newly-increased operation of data item in distributed system simultaneously When end system quantity is excessive, db transaction operation may generate identical timestamp, and the major key of database can occur at this time Conflict is based on this, on the basis of timestamp, splices to obtain final number with it using the customized serial number mechanism that program generates According to library major key, the specific procedure that wherein serial number generates are as follows:
private static Byte counter = 0;
public static int getCounter(){
if(counter == 99) counter = 0;
return counter++;
}。
5. a kind of database key generation method suitable for distributed system according to claim 1, which is characterized in that In the step (3), what the serial number and timestamp that program generates were spliced method particularly includes:
public static long getTimeInMillis(){
Calendar cal = Calendar.getInstance();
return cal.getTimeInMillis();
}
public static Long getTimeUID(){
return DateUtils.getTimeInMillis()*100 + getCounter();
}
public void save() {
if(this.notExisted()){
setId(DataUtils.getTimeUID());
}else{
LOGGER.info("object has existed().");
}
super.getRepository().save(this);
super.getRepository().flush();
}。
CN201810763653.3A 2018-07-12 2018-07-12 A kind of database key generation method suitable for distributed system Pending CN109241177A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810763653.3A CN109241177A (en) 2018-07-12 2018-07-12 A kind of database key generation method suitable for distributed system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810763653.3A CN109241177A (en) 2018-07-12 2018-07-12 A kind of database key generation method suitable for distributed system

Publications (1)

Publication Number Publication Date
CN109241177A true CN109241177A (en) 2019-01-18

Family

ID=65072505

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810763653.3A Pending CN109241177A (en) 2018-07-12 2018-07-12 A kind of database key generation method suitable for distributed system

Country Status (1)

Country Link
CN (1) CN109241177A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115277239A (en) * 2022-08-02 2022-11-01 恒生电子股份有限公司 Database data encryption method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102880705A (en) * 2012-09-28 2013-01-16 用友软件股份有限公司 Database primary key generating device and database primary key generating method
CN107454203A (en) * 2017-07-19 2017-12-08 成都数联铭品科技有限公司 The method for generating unique ID in a distributed system
CN107800733A (en) * 2016-08-31 2018-03-13 阿里巴巴集团控股有限公司 The generation method and equipment of session identification in distributed system
CN108241715A (en) * 2016-12-27 2018-07-03 苏宁云商集团股份有限公司 A kind of distributed data base major key generation method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102880705A (en) * 2012-09-28 2013-01-16 用友软件股份有限公司 Database primary key generating device and database primary key generating method
CN107800733A (en) * 2016-08-31 2018-03-13 阿里巴巴集团控股有限公司 The generation method and equipment of session identification in distributed system
CN108241715A (en) * 2016-12-27 2018-07-03 苏宁云商集团股份有限公司 A kind of distributed data base major key generation method and device
CN107454203A (en) * 2017-07-19 2017-12-08 成都数联铭品科技有限公司 The method for generating unique ID in a distributed system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115277239A (en) * 2022-08-02 2022-11-01 恒生电子股份有限公司 Database data encryption method and device
CN115277239B (en) * 2022-08-02 2023-12-05 恒生电子股份有限公司 Encryption method and device for database data

Similar Documents

Publication Publication Date Title
US11663090B2 (en) Method and system for desynchronization recovery for permissioned blockchains using bloom filters
US20220141018A1 (en) Method and system for an efficient consensus mechanism for permissioned blockchains using audit guarantees
US11640474B2 (en) Method and apparatus for operating database
US8626778B2 (en) System and method for conversion of JMS message data into database transactions for application to multiple heterogeneous databases
KR20210003234A (en) Maintaining blocks of a blockchain in a segmented blockchain network
CN103473696A (en) Method and system for collecting, analyzing and distributing internet business information
CN111597015A (en) Transaction processing method and device, computer equipment and storage medium
CN111625598B (en) Engineering collaboration block chain data structure and application method
CN110187831B (en) Block data storage system and method of block chain alliance chain
CN111026567B (en) Handle identification coding system and method based on block chain
CN110309173B (en) Contract data recording method and device, block chain node and storage medium
CN113110832A (en) Intelligent efficient code generation method and device and storage medium
CN109241177A (en) A kind of database key generation method suitable for distributed system
CN112258188A (en) Processing method, device, equipment and system for block chain transaction
CN116303789A (en) Parallel synchronization method and device for multi-fragment multi-copy database and readable medium
CN113810185B (en) Anti-trapdoor leakage on-chain data restoration system and method
CN111797166B (en) Method and device for synchronizing quasi-real-time resume data, electronic equipment and medium
CN110837536B (en) Information processing method, device and storage medium
WO2023232738A1 (en) Public verification of single consistent history of private ledgers
CN111767341A (en) Data synchronization method based on block chain
CN116260586A (en) Cross-chain-oriented digital signature algorithm updating system and method
Durov Catchain Consensus: An Outline
CN115827634A (en) Data conversion method, device and storage medium
CN118312518A (en) Distributed ID generation method and system
CN118103844A (en) Decentralised configuration integrity checking in a microservice environment

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
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20190118

WD01 Invention patent application deemed withdrawn after publication