CN111324619B - 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 PDFInfo
- Publication number
- CN111324619B CN111324619B CN202010099671.3A CN202010099671A CN111324619B CN 111324619 B CN111324619 B CN 111324619B CN 202010099671 A CN202010099671 A CN 202010099671A CN 111324619 B CN111324619 B CN 111324619B
- Authority
- CN
- China
- Prior art keywords
- data structure
- updated
- current data
- field
- decoding
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 54
- 238000013507 mapping Methods 0.000 claims description 8
- 238000004590 computer program Methods 0.000 claims description 6
- 230000008569 process Effects 0.000 abstract description 8
- 238000011161 development Methods 0.000 description 8
- 230000008859 change Effects 0.000 description 6
- 238000010586 diagram Methods 0.000 description 4
- 230000005540 biological transmission Effects 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 2
- 230000008021 deposition Effects 0.000 description 2
- 238000005538 encapsulation Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000002688 persistence Effects 0.000 description 2
- 230000004044 response Effects 0.000 description 2
- 238000009825 accumulation Methods 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000037430 deletion Effects 0.000 description 1
- 230000002349 favourable effect Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000010295 mobile communication Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
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
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;
an updating module, configured to maintain the positions of the elements associated with the encoding and decoding order unchanged, and update the current data structure with the elements to be updated;
and the generating module is used for generating a new universal 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, an 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 an encoding and decoding rule 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 structures related to the present invention are shown in the drawings, not all of them.
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 flexible and changeable service systems. The business middle platform layer is mainly used for processing the encapsulation and the deposition of the business and mainly faces to the deposition and the accumulation of the business. 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 data transmission between the hierarchies is performed by using a common object, such as a common dao object.
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 field including a field type (Int 32, string), a property 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 microservices, it is difficult to adjust the database, such as adding fields, changing fields, and deleting fields, during the service change. The data structure of the generic object should 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 which needs to be updated on the basis of the current data structure, and the element 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 (comprising the field name, the field type and the field attribute) in each data table. The nomenclature of the data structure is hump nomenclature.
And 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 field types and the attribute names 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 that meet 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 order is consistent with the field order, and is the order of 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 processing is finished, the field type and the attribute name of the field (the identifier is 2) arranged at the second position in the slice are obtained, and the like 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 current data structure with the current data structure according to the coding and decoding sequence of the fields in the slice of the data structure meeting the service requirement and the field type and the attribute name to determine the elements 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 at both ends are different, 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 following operations:
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. Taking the 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, which ensures 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 in the current data structure is changed. This operation is applicable to a case where only the attribute name of a 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 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 the 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 protoc (compiler of protobuf) file may be used to translate the proto description file into source codes corresponding to various programming languages, including data type definitions, call interfaces, and the like. 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 for 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 coding and decoding sequence in the current data structure according to the coding and decoding rules of the universal object, maintaining the positions of the elements associated with the coding 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, simple field attribute change and field type and attribute change for the current data structure, covers most database adjusting 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 further, by updating the field type and/or the attribute name in the current data structure, the updating fine granularity 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 the comparison and the update of the data structure are facilitated, and the object update 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 foregoing 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 into 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. If the file state is not updated, which indicates that the local version is the latest version that is trustworthy, the local data structure definition file of the generic object is obtained. It should be noted that the local version is also derived from the microservice system substantially, but only the latest version of the data structure definition file pulled from the microservice system at a historical time.
Optionally, the object update apparatus 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 a user inputs a version judgment and control instruction, for example, x, the object updating apparatus in the micro service system acquires the latest version of the data structure definition file of the general object from the micro service 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 and acquires the 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, the abstract syntax tree of the intermediate file is analyzed 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 the protobuf, and then each node of an abstract syntax tree of the intermediate file is parsed to find a structure (struct) corresponding to the structure, 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 structure. 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 coding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated.
And S260, generating a new universal 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 latest version of the data structure definition file 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 universal 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 can not be executed but the version judgment operation is directly obtained from the local place, and 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 coding and decoding sequence in the current data structure according to the coding and decoding rules of the universal object, maintaining the positions of the elements associated with the coding and decoding sequence unchanged, and updating the current data structure by adopting the elements to be updated; the method can update the current data structure by adopting the database on the premise of keeping the positions of elements related to 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 also be read by required services, recompilation of the services is not needed, the human resource consumption 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 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 a 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 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 is used as a computer-readable storage medium for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the object update method in the microservice 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 update apparatus in the microservice 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 also provides a computer-readable storage medium having a computer program stored thereon, where the computer program is used when executed by a computer processor to execute an object updating method in a microservice system, 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 coding 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 or portions thereof contributing to the prior art may be embodied in the form of a software product, which can 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 of 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 description is only exemplary of the invention and that the principles of the technology may be 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 some detail by the above embodiments, the invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the invention, and the scope of the 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; the current data structure includes at least one field;
determining an element to be updated according to the database of the micro service system; the element to be updated refers to an element needing to be updated on the basis of the current data structure;
determining elements related to coding and decoding sequences in the current data structure according to coding and decoding rules of the universal object; the elements related to the coding and decoding sequence comprise types of fields and identifiers respectively corresponding to the fields;
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 identifier is used to identify a field upon 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 the intermediate file is obtained by compiling the data structure definition file of the universal object.
6. The method according to claim 5, characterized in that 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;
or,
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 structure 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 current data structure includes at least one field;
the first determining module is used for determining an element to be updated according to the database of the micro-service system; the element to be updated refers to an element needing to be updated on the basis of the current data structure;
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 elements related to the coding and decoding sequence comprise types of fields and identifiers respectively corresponding to the fields;
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,
the 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.
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 CN111324619A (en) | 2020-06-23 |
CN111324619B true 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) |
Families Citing this family (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112291235B (en) * | 2020-10-28 | 2022-06-07 | 泰华智慧产业集团股份有限公司 | Internet of things equipment protocol coding and decoding method and device adaptive to micro-service architecture |
CN113553333B (en) * | 2021-07-20 | 2024-06-04 | 杭州网易云音乐科技有限公司 | Data operation method, device, equipment and medium of database |
CN113608768A (en) * | 2021-08-10 | 2021-11-05 | 杭州每刻科技有限公司 | Service interface update method and system based on gRPC microservice |
CN118829978A (en) * | 2022-03-30 | 2024-10-22 | 华为技术有限公司 | Data transmission method and device |
CN114995796B (en) * | 2022-05-30 | 2024-07-19 | 宁波三星医疗电气股份有限公司 | A-XDR (advanced digital Signal processor) coding message processing method, storage medium and electronic equipment |
Citations (3)
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 |
-
2020
- 2020-02-18 CN CN202010099671.3A patent/CN111324619B/en active Active
Patent Citations (3)
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 |
Also Published As
Publication number | Publication date |
---|---|
CN111324619A (en) | 2020-06-23 |
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 | |
US9110945B2 (en) | Support for a parameterized query/view in complex event processing | |
CN112394942A (en) | Distributed software development compiling method and software development platform based on cloud computing | |
US20220138074A1 (en) | Method, electronic device and computer program product for processing data | |
CN113238740A (en) | Code generation method, code generation device, storage medium, and electronic apparatus | |
CN113901083A (en) | Heterogeneous data source operation resource analysis positioning method and equipment based on multiple analyzers | |
CN111240772A (en) | Data processing method and device based on block chain and storage medium | |
CN116360735A (en) | Form generation method, device, equipment and medium | |
CN114173355A (en) | Dynamic execution method and system for network instruction with separated design operation state | |
CN116841900A (en) | Interface document, test case generation method, test case generation device, computer equipment and storage medium | |
CN116775613A (en) | Data migration method, device, electronic equipment and computer readable medium | |
CN114625373A (en) | Application conversion method and device, electronic equipment and storage medium | |
CN112711602B (en) | Method and device for running stored procedure, database system and storage medium | |
CN115794637A (en) | Method, device, equipment and computer readable medium for automatic test | |
CN110471708B (en) | Method and device for acquiring configuration items based on reusable components | |
CN113190236A (en) | HQL script checking method and device | |
CN117093638B (en) | Micro-service data initialization method, system, electronic equipment and storage medium | |
CN118363649B (en) | APK file fusion method, device, equipment and medium | |
CN108459914B (en) | Middleware command execution method and device | |
US12216627B2 (en) | Systems and methods for providing a database driver management architecture | |
CN118820122B (en) | Maven project dependency relationship static analysis method, device, equipment and storage medium | |
CN116225403A (en) | Domain-specific language data processing method and device, computing device and storage medium | |
CN117111898A (en) | Construction method and device of business model | |
CN119449900A (en) | Communication method and device based on graphic modeling |
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 |