CN111324619A - Object updating method, device, equipment and storage medium in micro service system - Google Patents

Object updating method, device, equipment and storage medium in micro service system Download PDF

Info

Publication number
CN111324619A
CN111324619A CN202010099671.3A CN202010099671A CN111324619A CN 111324619 A CN111324619 A CN 111324619A CN 202010099671 A CN202010099671 A CN 202010099671A CN 111324619 A CN111324619 A CN 111324619A
Authority
CN
China
Prior art keywords
data structure
updated
current data
field
file
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.)
Granted
Application number
CN202010099671.3A
Other languages
Chinese (zh)
Other versions
CN111324619B (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.)
Suzhou Dajiaying Information Technology Co Ltd
Original Assignee
Suzhou Dajiaying Information Technology 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 Suzhou Dajiaying Information Technology Co Ltd filed Critical Suzhou Dajiaying Information Technology Co Ltd
Priority to CN202010099671.3A priority Critical patent/CN111324619B/en
Publication of CN111324619A publication Critical patent/CN111324619A/en
Application granted granted Critical
Publication of CN111324619B publication Critical patent/CN111324619B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/23Updating

Abstract

The embodiment of the invention discloses an object updating method, device, equipment and storage medium in a micro service system. The method comprises the following steps: acquiring a current data structure of the general object from the micro service system; determining an element to be updated according to a database of the micro service system; and maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated to generate a new general object. The embodiment of the invention can update the current data structure by adopting the database on the premise of keeping the element position associated with the coding and decoding sequence unchanged, so that the updated data structure does not influence the coding and decoding sequence of the original data structure, the bytes of the original data structure are aligned in the process of transmitting the data stream of the universal object by adopting the sequential coding and decoding protocol, the updated data structure can be read by the required service, and the recompilation service is not needed.

Description

Object updating method, device, equipment and storage medium in micro service system
Technical Field
The embodiment of the invention relates to computer technology, in particular to a method, a device, equipment and a storage medium for updating an object in a micro service system.
Background
The micro-services were originally proposed by Martin Fowler and James Lewis in 2014, and the micro-service architecture style is a way to develop a single application using a set of small services, each of which runs in its own process and communicates using a lightweight mechanism.
In order to simplify the interactive interface inside the microservice system and improve the convenience of the program, a general object is adopted to transmit among all the layers of microservices. The generic object is generated by scanning a data structure of a database. Along with the development of various services, the database is inevitably adjusted in the service change process, and the data structure of the general object is correspondingly changed according to the adjustment of the database. In the process of transmitting the data stream of the general object by adopting the coding and decoding protocol, the bytes are not aligned, so that a large number of program errors occur.
The current solution is that when a business changes, all services related to a general business object are checked and recompiled, which consumes a large amount of human resources and affects the project development progress.
Disclosure of Invention
The embodiment of the invention provides an object updating method, device, equipment and storage medium in a micro service system, which are used for updating objects according to coding and decoding sequences when services are changed, recompiling of services is not needed, human resource consumption is reduced, and project development progress is improved.
In a first aspect, an embodiment of the present invention provides an object updating method in a microservice system, including:
acquiring a current data structure of the general object from the micro service system;
determining an element to be updated according to the database of the micro service system;
determining elements related to coding and decoding sequences in the current data structure according to coding and decoding rules of the universal object;
maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated;
and generating a new universal object by adopting the updated data structure.
In a second aspect, an embodiment of the present invention further provides an object updating apparatus in a microservice system, including:
the acquisition module is used for acquiring the current data structure of the general object from the micro service system;
the first determining module is used for determining an element to be updated according to the database of the micro service system;
a second determining module, configured to determine, according to the encoding and decoding rule of the generic object, an element associated with an encoding and decoding order in the current data structure;
the updating module is used for maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated;
and the generating module is used for generating a new general object by adopting the updated data structure.
In a third aspect, an embodiment of the present invention further provides an electronic device, where the electronic device includes:
one or more processors;
a memory for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the object update method in the microservice system according to any embodiment.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the object updating method in the microservice system according to any embodiment.
In the embodiment of the invention, the elements to be updated are determined according to the database of the micro-service system, and the current data structure is updated by adopting the elements to be updated, so that when the database is changed, the elements to be updated can be automatically determined, the current data structure is consistent with the data structure to be generated, and the recompilation service and the redefinition of a general object are not needed; determining elements associated with an encoding and decoding sequence in the current data structure according to encoding and decoding rules of the general object, maintaining the positions of the elements associated with the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated; on the premise of maintaining the positions of the elements related to the coding and decoding sequence unchanged, the current data structure is updated by the database, so that the coding and decoding sequence of the original data structure is not influenced by the updated data structure, the bytes of the original data structure are aligned in the process of transmitting the data stream of the universal object by adopting the sequential coding and decoding protocol, the updated data structure can also be read by the required service, recompilation of the service is not needed, the consumption of human resources is reduced, and the project development progress is improved.
Drawings
Fig. 1 is a flowchart of an object updating method in a microservice system according to an embodiment of the present invention;
fig. 2 is a flowchart of an object updating method in a microservice system according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of an object update apparatus in a microservice system according to a third embodiment of the present invention
Fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of an object updating method in a micro service system according to an embodiment of the present invention, which is applicable to a case of updating a general object in the micro service system, and is particularly applicable to a case of updating a general service object. The micro service system in this embodiment is a multi-layer structure designed for field driving, and includes, in order from top to bottom, a presentation layer (Present layer), a business middle platform layer (Bmp layer), and a Basic service layer (Basic layer). The presentation layer, the business middle platform layer and the basic service layer are units which are realized by corresponding logic codes, and each unit comprises a plurality of modules to realize corresponding functions. The presentation layer faces to a user and an interface (UI) and is responsible for interacting with the user, and the UI comprises a World Wide Web (Web) page, a mobile phone software page, an interface for a third party to call and the like, and is suitable for a flexible and changeable service system. The service middle layer is mainly used for processing encapsulation and deposition of services and mainly faces deposition and accumulation of services. The business middleware layer also includes asynchronous Message Queue (MQ) consumers. The basic service layer is oriented to a persistence layer, is mainly used for storing, updating and storing data and is oriented to a data structure. The persistence layer includes a Database (DB). The hierarchies employ common objects, such as common dao objects, for data transfer between them.
The method provided by the embodiment can be executed by an object updating device in the microservice system, and the device can be formed by hardware and/or software and is generally integrated in electronic equipment. The electronic device may be a node device in the micro service system, or may be a device independent of the micro service system, and is in communication connection with the micro service system.
With reference to fig. 1, the method for updating an object in a microservice system provided in the embodiment of the present invention specifically includes the following operations:
and S110, acquiring the current data structure of the general object from the micro service system.
In this step, the current data structure of the generic object is the data structure of the generic object at the current time, i.e. the latest data structure of the generic object.
The proto description file defines the data structure of the generic object. In an application scenario, the generic object may be a generic business object whose proto description file defines a data structure as follows:
Message xxx{
Int32 age=1;
String name=2;
String email=3;
}
the data structure includes 3 fields, each of which includes a field type (Int32, String), an attribute name (age, name, email), and an identifier (1, 2, 3).
And S120, determining the elements to be updated according to the database of the micro-service system.
With the development of multiple services in microservice, it is difficult to avoid adjusting the database during service changes, such as adding fields, changing fields, and deleting fields. The data structure of the universal object needs to be consistent with the data structure of the database to ensure the smooth development of the service, so that the element to be updated needs to be determined according to the database.
The element to be updated refers to an element needing to be updated on the basis of the current data structure, and comprises at least one of a deleted field, an added field and a changed field.
Optionally, the database of the microservice system is first scanned to determine the data structure that satisfies the business requirements. Specifically, scanning a database, acquiring each data table included in the database, and acquiring each field included in each data table; and obtaining at least one data structure meeting the service requirement according to each field (including the field name, the field type and the field attribute) in each data table. The nomenclature of the data structure is hump nomenclature.
Then, comparing the field type and the attribute name in the current data structure and the data structure meeting the service requirement, and determining the element to be updated. And if the number of the current data structures is multiple, comparing the field types and the attribute names according to the coding and decoding sequence aiming at each data structure by adopting the named index of the data structure.
Specifically, in order to improve the comparison efficiency, the types and the attribute names of the fields in the current data structure are stored in a key-value pair mapping (map) format, the fields are sequentially stored in a slice (slice) format, and the fields in the data structure meeting the service requirements are stored in the slice format. The Slice (Slice) is a variable-length sequence with elements of the same type, is a layer of encapsulation made based on an array type, and supports automatic capacity expansion. The key-value pair mapping (map) format includes a plurality of key-value pairs, a key representing the type of an element and a value representing the value of the element.
Optionally, at the outermost layer of the current data structure, storing a name and an attribute set of the current data structure as a key-value pair mapping format, where the attribute set includes a type and an attribute name of each field; and storing each field type and attribute name in the current data structure as a key-value pair mapping format. The key-value pair mapping format for storing a certain data structure is as follows:
var astMap map[string]*scan.ScanItem;
type ScanItem Struct{
InfoMap map[string]
InfoList*[]*FieldItem
}
the substructure FieldItem in map is as follows:
Type FieldItem struct{
VarName string// attribute name
VarType VarTypeEnum// enumeration
VarTypeString// field type
VarTag string// identifier
}
Wherein enumeration is used for recording field types, and judging whether the types are changed when the current data structure is updated by adopting elements to be updated.
The fields are stored sequentially in a slice (slice) format, for example the slice stores: VarName, VarType, VarTypeStr, Vartag.
And then, comparing the coding and decoding sequence of the fields in the slice of the current data structure with the field type and the attribute name in the data structure meeting the service requirement. The encoding and decoding sequence is consistent with the field sequence, and is the sequence for encoding/decoding each field of the data structure according to the encoding and decoding protocol. For example, the codec protocol is ProtoBuf. In top-down order, each field of the message corresponds to a key-value pair when serialized, and the whole binary file is a series of closely arranged key-value pairs. key | (field _ number < <3) | wire _ type, the field _ number section indicates which field is currently, i.e., the identification number of each field in the proto file. The ProtoBuf protocol is detailed in the prior art and is not described extensively herein. Specifically, the field type and the attribute name of a field (identifier is 1) arranged at the head in a slice of a current data structure are firstly obtained, then traversal is carried out in the data structure meeting the service requirement, and the same field type and the same attribute name are searched; and after the field type and the attribute name of the field (the identifier is 2) arranged at the second position in the slice are found, and the like is carried out until all the fields in the slice are processed. And if the comparison result is consistent after the fields in the slice are processed, indicating that no element to be updated exists. If the comparison result is inconsistent in the comparison process, stopping the comparison, and comparing the comparison result with the current data structure according to the field type and the attribute name according to the coding and decoding sequence of the fields in the slice of the data structure meeting the service requirement to determine the element to be updated. Specifically, the field type and the attribute name of a first-order field (identifier 1) in a slice of a data structure meeting the service requirement are obtained, and then traversal is performed in the current data structure to find an element to be updated.
S130, determining elements related to the coding and decoding sequence in the current data structure according to the coding and decoding rules of the universal object.
Taking ProtoBuf as an example, the encoding and decoding rule is to encode and decode the field types and the attribute names in the order from small identifiers to large identifiers to form a series of closely arranged key-values. Wherein the identifier and the field type constitute a key for identifying which field is decoded. Therefore, the identifier and the field type are determined as elements associated with the codec order.
S140, keeping the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated.
In this embodiment, on the basis of the current data structure, the element to be updated is used for updating. In an actual application scenario, at the time of decoding, protobuf reads the identifier from the input stream, and then sets the corresponding value in the message. If the read identifier is not present in the message, it is directly ignored, and if the identifier is not present in the input stream, the field is not set. Even if one of the two ends of the communication has more identifiers than the other, decoding is not affected. But if the field types of the same identifier are different at both ends, decoding is affected, resulting in byte misalignment. Therefore, the location of the identifier and field type should not change. In addition, the attribute name may be changed, and a new field may be added at the end of the current data structure, with the identifier of the new field extending. S140 includes at least one of:
the first method comprises the following steps: and if the element to be updated is the deleted field, setting the identifier corresponding to the deleted field as unavailable in the current data structure. This operation may preserve the attributes.
And the second method comprises the following steps: if the element to be updated is an added field, the added field is written to the end of the current data structure. Specifically, the type, attribute name, and identifier of the added field are written to the end of the current data structure, and the identifier is the identifier +1 in the current data structure. In the above Message xxx as an example, if the added field is a telephone number in a string format, string phoneNum 4 is added to the end of the Message xxx to ensure byte alignment of the original data structure, and the updated data structure (string phoneNum) can also be read by the required service.
And the third is that: if the element to be updated is a changed field and the current data structure has a changed field type, the attribute name of the changed field is changed in the current data structure. The operation is suitable for the case that only the attribute name of the field is changed and the field type is not changed. Since the field type is not changed, the method has no influence on the sequential coding and decoding. So the attribute name can be changed directly.
And fourthly: if the element to be updated is a changed field and the current data structure does not have a changed field type, writing the changed field into the tail end of the current data structure and setting the identifier of the original field as unavailable. This operation is applicable to the case where the field type is changed, and the attribute name may or may not be changed. Since a type change would affect the sequential codec, this field would need to be written to the end of the current data structure, like the added field.
Optionally, in the slice format, an added field is added to the slice using an ap-pend () method that appends the added field to the end of the slice of the current data structure and returns the slice. Under the key-value pair mapping format, the key-value pair of the added field is added to the current data structure.
And S150, generating a new universal object by adopting the updated data structure.
The updated data structure is encapsulated into a proto description file, which is a data structure definition file of a new generic object. Further, the proto description file is compiled to obtain a pb. In the microservice system, the general-purpose object needs to be encoded to enable the general-purpose object to be transmitted or stored on the network. Specifically, a proto (compiler of proto) can be used to translate proto description file into source code corresponding to various programming languages, including data type definition, call interface, etc. These intermediate documents are pb. In an application scenario where the common object is a CommonDao object, the intermediate file name is CommonDao.
In the embodiment, after the new intermediate file is generated, the new intermediate file is provided to the micro-service for data transmission; the proto description file may then be stored locally for generating intermediate files in multiple languages.
It is worth noting that if there are no elements to be updated, the current data structure is employed to generate a generic object. That is, the current data structure is encapsulated into a proto description file, which is compiled to get pb.
In the embodiment of the invention, the elements to be updated are determined according to the database of the micro-service system, and the current data structure is updated by adopting the elements to be updated, so that when the database is changed, the elements to be updated can be automatically determined, the current data structure is consistent with the data structure to be generated, and the recompilation service and the redefinition of a general object are not needed; determining elements associated with the encoding and decoding sequence in the current data structure according to the encoding and decoding rules of the universal object, maintaining the positions of the elements associated with the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated; the method has the advantages that the current data structure can be updated by the database on the premise that the positions of elements related to the coding and decoding sequence are not changed, so that the coding and decoding sequence of the original data structure is not influenced by the updated data structure, the bytes of the original data structure are aligned in the process of transmitting the data stream of the universal object by adopting the sequential coding and decoding protocol, the updated data structure can be read by needed services, recompilation of the services is not needed, the consumption of human resources is reduced, and the project development progress is improved.
Further, the embodiment also provides an updating method in 4 of field deletion, field addition, field attribute simple change and field type and attribute change for the current data structure, which covers most of database adjustment means and is suitable for various service scenes.
Further, a data structure meeting business requirements is determined by scanning a database of the micro-service system; comparing the field type and the attribute name in the current data structure and the data structure meeting the service requirement, and determining the element to be updated, so that the element to be updated is determined by comparing the field type and the attribute name in the data structure, and the comparison efficiency and accuracy can be improved; and then, by updating the field type and/or the attribute name in the current data structure, the fine granularity of the update of the object is changed to the type and the attribute name, so that the small-range adjustment of the service is facilitated.
Furthermore, the data structure is stored into a map format and a slice format, so that comparison and updating of the data structure are facilitated, and the object updating efficiency is improved.
Example two
Fig. 2 is a flowchart of an object updating method in the microservice system according to a second embodiment of the present invention. The present embodiment optimizes the above embodiments, and specifically limits the operation of acquiring the current data structure.
The method as shown in fig. 2 comprises the following operations:
s210, acquiring the latest version of the data structure definition file of the general object from the micro service system, and compiling the data structure definition file to obtain an intermediate file.
Optionally, a version control system, such as git, is built in the microservice system. git is an open source distributed version control system, a system that records one or several file content changes in order to refer to the revision of a particular version in the future. The git in this embodiment is mounted on a data structure definition file (i.e., proto description file), and based on this, the latest version of the data structure definition file of the current generic object is obtained from git, and the data structure definition file is compiled to obtain an intermediate file.
This embodiment provides two methods for obtaining the data structure definition file from git, one is to obtain the latest version of the data structure definition file of the general object from the remote repository of the version control system. The remote repository refers to a version repository of a specified file hosted in the internet or other network, in which the latest version of the data structure definition file is stored, so that the latest version of the data structure definition file can be directly obtained from the remote repository to the local repository. Optionally, the local repository needs to register the account number of the remote repository and set the key to connect with the remote repository, and encrypted transmission is performed between the local repository and the remote repository.
Another approach is to look at the file state of the data structure definition file. If the file state is updated, pulling the data structure definition file of the latest version of the general object from the remote warehouse; and if the file state is not updated, acquiring the data structure definition file of the local general object. In particular, executing the command line git fetch < remote warehouse name > retrieves all updated versions of the remote warehouse locally, but not merged locally. The git status is then executed to obtain the file status of the data structure definition file to decide that the updated version cannot be merged locally. And if the file state is updated, which indicates that the updated version of the remote warehouse is newer than the local version, the updated version cannot be merged locally, and an alarm message is sent to the user to prompt the user to manually pull the data structure definition file of the latest version of the general object from the remote warehouse. And if the file state is not updated, which indicates that the local version is the latest version which is trustworthy, acquiring the local data structure definition file of the general object. It should be noted that the local version is also substantially derived from the microservice system, and is only the latest version of the data structure definition file pulled from the microservice system at the historical time.
Optionally, the object updating device in the microservice system provides a command line entry, and can receive an instruction transmitted from the outside. In this embodiment, the user can control whether the object update apparatus in the microservice system performs version judgment and control through the command line entry. If the user inputs a version judgment and control instruction, for example, x, the object updating apparatus in the microservice system acquires the latest version of the data structure definition file of the common object from the microservice system in response to the version judgment and control instruction of the user. If the user inputs a non-version judgment and control instruction, such as-x, the object updating device in the micro service system responds to the non-version judgment and control instruction of the user to acquire a local data structure definition file of the general object.
Alternatively, the user may control whether to perform the update operation of the common object through the command line entry. Specifically, if a user inputs an update instruction, for example, a, the object update apparatus in the micro service system executes the object update method in the micro service system provided in any embodiment of the present invention in response to the update instruction of the user, so that the user can autonomously and flexibly execute the method provided in any embodiment of the present invention.
And S220, analyzing the intermediate file to obtain the current data structure of the universal object.
Because the intermediate file is obtained by compiling the definition file of the data structure and contains the current data structure, the current data structure of the universal object can be analyzed from the intermediate file.
Optionally, parsing the abstract syntax tree of the intermediate file to find a structure corresponding to the structural body; and carrying out recursive analysis on the structure corresponding to the structure body to obtain the current data structure of the universal object.
In computer science, an Abstract Syntax Tree (AST), or simply Syntax Tree (Syntax Tree), is an Abstract representation of the Syntax structure of source code. It represents the syntactic structure of the programming language in the form of a tree, each node on the tree representing a structure in the source code. Specifically, an intermediate file is found in a directory of protobuf, and then each node of an abstract syntax tree of the intermediate file is parsed to find a structure corresponding to a structure (struct), that is, a member in the structure. Then, the structure corresponding to the structure is recursively analyzed. Specifically, each member is parsed, and if the member is a nested structure name, the structure corresponding to the structure continues to be parsed. And after the member analysis is completed, returning to analyze the next member of the member until all the members are analyzed, and realizing the recursive analysis of the structural body. And after the analysis is finished, obtaining at least one structural body, wherein each structural body comprises at least one field, and each field comprises a field type, attribute name enumeration and an identifier.
The structure obtained by analysis can be stored in a map format and a slice format, which facilitates comparison and update of the data structure, and specific details are described in the above embodiments and are not repeated here.
And S230, determining the elements to be updated according to the database of the micro-service system.
S240, determining elements related to the coding and decoding sequence in the current data structure according to the coding and decoding rules of the universal object.
And S250, maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated.
And S260, generating a new general object by adopting the updated data structure.
In the embodiment, the latest timeliness of the intermediate file is ensured by obtaining the data structure definition file and compiling the data structure definition file to obtain the intermediate file.
Furthermore, a version control system is built in the micro service system, so that the data structure definition file of the latest version is obtained, the intermediate file processed by the embodiment and the intermediate file transmitted in the micro service system are ensured to be the same version, and the availability of the intermediate file is ensured.
Further, acquiring a data structure definition file of the latest version of the general object from the micro service system by responding to a version judgment and control instruction of a user; and responding to the non-version judgment and control instruction of the user, and acquiring the data structure definition file of the local general object, so that the user can autonomously and flexibly control whether to judge the version. Under the condition that the version updating is not needed, the version judgment operation is not executed, and the version judgment operation can be directly obtained from the local place, so that the object updating efficiency is improved.
Furthermore, the structure corresponding to the structure body is found by analyzing the abstract syntax tree of the intermediate file, and the structure corresponding to the structure body is subjected to recursive analysis to obtain the current data structure of the universal object, so that the abstract syntax book and the recursive analysis are analyzed, the method is favorable for accurately and comprehensively finding all the structure bodies, and the object updating accuracy is improved.
EXAMPLE III
Fig. 3 is a schematic structural diagram of an object updating apparatus in a microservice system according to a third embodiment of the present invention, which is applicable to a case of updating a general object in the microservice system, and is particularly applicable to a case of updating a general service object. The object updating apparatus in the microservice system shown in fig. 3 includes: an obtaining module 31, a first determining module 32, a second determining module 33, an updating module 34 and a generating module 35.
An obtaining module 31, configured to obtain a current data structure of the generic object from the micro service system;
a first determining module 32, configured to determine an element to be updated according to a database of the microservice system;
a second determining module 33, configured to determine, according to the encoding and decoding rule of the generic object, an element associated with an encoding and decoding order in the current data structure;
an update module 34, configured to maintain a position of an element associated with the encoding and decoding order unchanged, and update the current data structure with an element to be updated;
and a generating module 35, configured to generate a new general object by using the updated data structure.
In the embodiment of the invention, the elements to be updated are determined according to the database of the micro-service system, and the current data structure is updated by adopting the elements to be updated, so that when the database is changed, the elements to be updated can be automatically determined, the current data structure is consistent with the data structure to be generated, and the recompilation service and the redefinition of a general object are not needed; determining elements associated with the encoding and decoding sequence in the current data structure according to the encoding and decoding rules of the universal object, maintaining the positions of the elements associated with the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated; the method has the advantages that the current data structure can be updated by the database on the premise that the positions of elements related to the coding and decoding sequence are not changed, so that the coding and decoding sequence of the original data structure is not influenced by the updated data structure, the bytes of the original data structure are aligned in the process of transmitting the data stream of the universal object by adopting the sequential coding and decoding protocol, the updated data structure can be read by needed services, recompilation of the services is not needed, the consumption of human resources is reduced, and the project development progress is improved.
Optionally, the current data structure comprises at least one field; the elements associated with the coding and decoding order comprise the types of the fields and identifiers respectively corresponding to the fields, and the identifiers are used for identifying the fields during decoding; based on this, the update module 34 is specifically configured to perform at least one of the following operations: if the element to be updated is the deleted field, setting the identifier corresponding to the deleted field as unavailable in the current data structure; if the element to be updated is an increased field, writing the increased field into the tail of the current data structure; if the element to be updated is a changed field and the current data structure has a changed field type, changing the attribute name of the changed field in the current data structure; if the element to be updated is a changed field and the current data structure does not have a changed field type, writing the changed field into the tail end of the current data structure and setting the identifier of the original field as unavailable.
Optionally, the first determining module 32 is specifically configured to scan a database of the microservice system and determine a data structure meeting the business requirement; and comparing the field type and the attribute name in the current data structure and the data structure meeting the service requirement, and determining the element to be updated.
Optionally, when comparing the field type and the attribute name in the current data structure and the data structure meeting the service requirement and determining the element to be updated, the first determining module 32 is specifically configured to: storing each field type and attribute name in the current data structure as a key-value pair mapping format, and sequentially storing the fields as a slice format; storing each field in a data structure meeting the service requirement into a slice format; comparing the coding and decoding sequence of fields in the slice of the current data structure with the data structure meeting the service requirement according to the field type and the attribute name; and if the comparison result is inconsistent, comparing the coding and decoding sequence of the fields in the slice of the data structure meeting the service requirement with the current data structure according to the field type and the attribute name, and determining the element to be updated.
Optionally, the obtaining module 31 is specifically configured to obtain the latest version of the data structure definition file of the general object from the micro service system, and compile the data structure definition file to obtain an intermediate file; analyzing the intermediate file to obtain the current data structure of the universal object; the intermediate file is obtained by compiling the data structure definition file of the universal object.
Optionally, a version control system is built in the micro service system; based on this, when acquiring the latest version of the data structure definition file of the generic object from the microservice system, the acquiring module 31 is specifically configured to: acquiring a data structure definition file of the latest version of the general object from a remote warehouse of a version control system; or, in particular, for: viewing a file state of the data structure definition file; if the file state is updated, pulling the data structure definition file of the latest version of the general object from the remote warehouse; and if the file state is not updated, acquiring the data structure definition file of the local general object.
Optionally, the obtaining module 31, when obtaining the latest version of the data structure definition file of the generic object from the micro service system, is specifically configured to: responding to the version judgment and control instruction of the user, and acquiring a data structure definition file of the latest version of the general object from the micro service system; and responding to the non-version judgment and control instruction of the user, and acquiring the data structure definition file of the local general object.
Optionally, when the obtaining module 31 parses the intermediate file to obtain the current data structure of the general object, it is specifically configured to: analyzing the abstract syntax tree of the intermediate file to find a structure corresponding to the structural body; and carrying out recursive analysis on the structure corresponding to the structure body to obtain the current data structure of the universal object.
The object updating device in the micro service system provided by the embodiment of the invention can execute the object updating method in the micro service system provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention, as shown in fig. 4, the electronic device includes a processor 40, a memory 41; the number of the processors 40 in the electronic device may be one or more, and one processor 40 is taken as an example in fig. 4; the processor 40 and the memory 41 in the electronic device may be connected by a bus or other means, and fig. 4 illustrates the connection by the bus as an example.
The memory 41 serves as a computer-readable storage medium, and may be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the object updating method in the micro service system in the embodiment of the present invention (for example, the obtaining module 31, the first determining module 32, the second determining module 33, the updating module 34, and the generating module 35 in the object updating apparatus in the micro service system). The processor 40 executes various functional applications and data processing of the electronic device by executing software programs, instructions and modules stored in the memory 41, that is, implements the object update method in the microservice system described above.
The memory 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 41 may further include memory located remotely from processor 40, which may be connected to the electronic device through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
EXAMPLE five
An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, where the computer program is used for executing an object updating method in a microservice system when executed by a computer processor, and the method includes:
acquiring a current data structure of the general object from the micro service system;
determining an element to be updated according to a database of the micro service system;
determining elements related to the coding and decoding sequence in the current data structure according to the coding and decoding rules of the universal object;
maintaining the positions of elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated;
and generating a new universal object by adopting the updated data structure.
Of course, the computer program provided by the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the object updating method in the microservice system provided by any embodiments of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the embodiment of the object update apparatus in the microservice system, the included units and modules are only divided according to the functional logic, but are not limited to the above division as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (11)

1. An object updating method in a micro service system is characterized by comprising the following steps:
acquiring a current data structure of the general object from the micro service system;
determining an element to be updated according to the database of the micro service system;
determining elements related to coding and decoding sequences in the current data structure according to coding and decoding rules of the universal object;
maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated;
and generating a new universal object by adopting the updated data structure.
2. The method of claim 1, wherein the current data structure comprises at least one field; the elements related to the coding and decoding sequence comprise types of fields and identifiers respectively corresponding to the fields, wherein the identifiers are used for identifying the fields during decoding;
the maintaining the positions of the elements associated with the coding and decoding order unchanged, and updating the current data structure by using the elements to be updated, include at least one of the following operations:
if the element to be updated is a deleted field, setting an identifier corresponding to the deleted field in the current data structure as unavailable;
if the element to be updated is an added field, writing the added field into the tail end of the current data structure;
if the element to be updated is a changed field and the current data structure has the changed field type, changing the attribute name of the changed field in the current data structure;
and if the element to be updated is a changed field and the current data structure does not have the changed field type, writing the changed field into the tail end of the current data structure, and setting the identifier of the original field as unavailable.
3. The method of claim 1, wherein determining the elements to be updated from the database of the microservice system comprises:
scanning a database of the micro-service system, and determining a data structure meeting business requirements;
and comparing the field types and the attribute names in the current data structure and the data structure meeting the service requirements, and determining the elements to be updated.
4. The method according to claim 3, wherein the comparing the field type and the attribute name in the current data structure and the data structure satisfying the service requirement to determine the element to be updated comprises:
storing each field type and attribute name in the current data structure as a key-value pair mapping format, and sequentially storing the fields as a slice format;
storing each field in the data structure meeting the service requirement into a slice format;
comparing the coding and decoding sequence of the fields in the slice of the current data structure with the data structure meeting the service requirement according to the field type and the attribute name;
and if the comparison result is inconsistent, comparing the coding and decoding sequence of the fields in the slice of the data structure meeting the service requirement with the current data structure according to the field type and the attribute name, and determining the element to be updated.
5. The method of any of claims 1-4, wherein obtaining the current data structure of the generic object from the microservice system comprises:
acquiring a data structure definition file of the latest version of the general object from the micro-service system, and compiling the data structure definition file to obtain an intermediate file;
analyzing the intermediate file to obtain the current data structure of the universal object;
and compiling the intermediate file by compiling the data structure definition file of the universal object.
6. The method according to claim 5, wherein a version control system is built in the microservice system;
the obtaining a latest version of the data structure definition file of the generic object from the microservice system includes:
acquiring a data structure definition file of the latest version of the general object from a remote warehouse of the version control system;
alternatively, the first and second electrodes may be,
the obtaining a latest version of the data structure definition file of the generic object from the microservice system includes:
viewing the file state of the data structure definition file;
if the file state is updated, pulling the latest version of the data structure definition file of the general object from a remote warehouse;
and if the file state is not updated, acquiring a data structure definition file of the local general object.
7. The method of claim 5, wherein the obtaining a latest version of the data structure definition file of the generic object from the microservice system comprises:
responding to a version judgment and control instruction of a user, and acquiring a data structure definition file of the latest version of the general object from the micro service system;
and responding to the non-version judgment and control instruction of the user, and acquiring a local data structure definition file of the universal object.
8. The method of claim 5, wherein parsing the intermediate file to obtain the current data structure of the generic object comprises:
analyzing the abstract syntax tree of the intermediate file to find a structure corresponding to the structural body;
and carrying out recursive analysis on the structure corresponding to the structural body to obtain the current data structure of the universal object.
9. An object updating apparatus in a microservice system, comprising:
the acquisition module is used for acquiring the current data structure of the general object from the micro service system;
the first determining module is used for determining an element to be updated according to the database of the micro service system;
a second determining module, configured to determine, according to the encoding and decoding rule of the generic object, an element associated with an encoding and decoding order in the current data structure;
the updating module is used for maintaining the positions of the elements related to the encoding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated;
and the generating module is used for generating a new general object by adopting the updated data structure.
10. An electronic device, characterized in that the device comprises:
one or more processors;
a memory for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the object update method in the microservice system of any of claims 1-8.
11. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method for object update in a microservice system according to any one of claims 1 to 8.
CN202010099671.3A 2020-02-18 2020-02-18 Object updating method, device, equipment and storage medium in micro-service system Active CN111324619B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010099671.3A CN111324619B (en) 2020-02-18 2020-02-18 Object updating method, device, equipment and storage medium in micro-service system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010099671.3A CN111324619B (en) 2020-02-18 2020-02-18 Object updating method, device, equipment and storage medium in micro-service system

Publications (2)

Publication Number Publication Date
CN111324619A true CN111324619A (en) 2020-06-23
CN111324619B CN111324619B (en) 2022-10-28

Family

ID=71171046

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010099671.3A Active CN111324619B (en) 2020-02-18 2020-02-18 Object updating method, device, equipment and storage medium in micro-service system

Country Status (1)

Country Link
CN (1) CN111324619B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112291235A (en) * 2020-10-28 2021-01-29 泰华智慧产业集团股份有限公司 Internet of things equipment protocol coding and decoding method and device adaptive to micro-service architecture
CN113553333A (en) * 2021-07-20 2021-10-26 杭州网易云音乐科技有限公司 Data operation method, device, equipment and medium of database
CN113608768A (en) * 2021-08-10 2021-11-05 杭州每刻科技有限公司 Service interface updating method and system based on gPRC micro service
WO2023184285A1 (en) * 2022-03-30 2023-10-05 华为技术有限公司 Data transmission method and apparatus

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002063494A2 (en) * 2001-02-05 2002-08-15 Koninklijke Philips Electronics N.V. Object transfer method with format adaptation
CN103064712A (en) * 2012-12-28 2013-04-24 深圳市共进电子股份有限公司 Method, device and terminal device for updating configuration parameter
CN110018822A (en) * 2019-04-16 2019-07-16 山东浪潮通软信息科技有限公司 A kind of method and system automatically generating micro services function

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002063494A2 (en) * 2001-02-05 2002-08-15 Koninklijke Philips Electronics N.V. Object transfer method with format adaptation
CN103064712A (en) * 2012-12-28 2013-04-24 深圳市共进电子股份有限公司 Method, device and terminal device for updating configuration parameter
CN110018822A (en) * 2019-04-16 2019-07-16 山东浪潮通软信息科技有限公司 A kind of method and system automatically generating micro services function

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112291235A (en) * 2020-10-28 2021-01-29 泰华智慧产业集团股份有限公司 Internet of things equipment protocol coding and decoding method and device adaptive to micro-service architecture
CN113553333A (en) * 2021-07-20 2021-10-26 杭州网易云音乐科技有限公司 Data operation method, device, equipment and medium of database
CN113608768A (en) * 2021-08-10 2021-11-05 杭州每刻科技有限公司 Service interface updating method and system based on gPRC micro service
WO2023184285A1 (en) * 2022-03-30 2023-10-05 华为技术有限公司 Data transmission method and apparatus

Also Published As

Publication number Publication date
CN111324619B (en) 2022-10-28

Similar Documents

Publication Publication Date Title
CN111324619B (en) Object updating method, device, equipment and storage medium in micro-service system
US10630614B2 (en) Opaque message parsing
CN112738216B (en) Equipment adaptation method, device, equipment and computer readable storage medium
CN112540862A (en) Interface document data generation method, device, equipment and storage medium
CN112394942A (en) Distributed software development compiling method and software development platform based on cloud computing
US11934287B2 (en) Method, electronic device and computer program product for processing data
CN112306884A (en) Program test control and execution method and corresponding device, equipment and medium
CN113238740A (en) Code generation method, code generation device, storage medium, and electronic apparatus
CN111240772A (en) Data processing method and device based on block chain and storage medium
CN111552839A (en) Object conversion method based on XML template
CN111158777A (en) Component calling method and device and computer readable storage medium
CN114625373A (en) Application conversion method and device, electronic equipment and storage medium
CN114780800A (en) Multilink routing management method and device
CN112711602B (en) Method and device for running stored procedure, database system and storage medium
CN110471708B (en) Method and device for acquiring configuration items based on reusable components
CN108595166B (en) Method and system for realizing application execution engine of distributed Internet of things
CN113050987A (en) Interface document generation method and device, storage medium and electronic equipment
CN114371982A (en) Simulation test method, device, equipment and readable storage medium
CN117093638B (en) Micro-service data initialization method, system, electronic equipment and storage medium
CN108459914B (en) Middleware command execution method and device
CN116225403A (en) Domain-specific language data processing method and device, computing device and storage medium
CN116107588A (en) Program language conversion method, apparatus, device, medium, and program product
CN113703729A (en) Method, device and equipment for generating program call chain
CN113110873A (en) Method and apparatus for unifying system coding specifications
CN117111898A (en) Construction method and device of business model

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