Conflict-free write operations in multi-master database
A method for operating a multi-master database includes defining a database cluster having a plurality of databases. Each database is assigned to a corresponding geographic region. Read/write requests originating from a user are assigned to a database with the same corresponding geographic region as the user. The database cluster defines a schema including defined relationships between data records stored in the database cluster such that each data record stored in the database cluster is within a data cluster. Each data cluster includes a single parent data record replicated in each database of the database cluster. Each data cluster defines a single master database of the plurality of databases. The single master database is the database originating the single parent data record.
1 . A computer-implemented method for operating a multi-master database system comprising:
defining a database system having a plurality of databases, with each database being assigned to a corresponding geographic region, wherein read/write requests originating from a user are assigned to a database in the plurality of databases with the same corresponding geographic region as the user;
the database system defining having a defined schema, the defined schema including relationships between data records stored in the database system such that each data record stored in the database system is within a data cluster, each data cluster includes a single parent data record and a plurality of child data records, wherein each parent data record is replicated in each database of the database system, and each data cluster defines a single master database of the plurality of databases such that each data cluster in the database system defines a same database of the plurality of databases as the single master database and, wherein the single master database is the database of the plurality of databases originating the single parent data record;
replicating a write operation from a database of the plurality of databases to each other database of the plurality of databases by:
determining that the database of the plurality of databases in which the write operation is being replicated from is not a parent's master database of the data record being operated by the write operation;
replicating the write operation to the parent's master database of the data record being operated by the write operation; and
replicating the write operation to each other database in the plurality of databases from the parent's master database of the data record being operated by the write operation.
2 . The computer-implemented method of claim 1 , wherein the single master database corresponding to each data cluster is the database of the plurality of databases assigned to the geographic region from which a write request creating the data cluster originates.
3 . The computer-implemented method of claim 1 , wherein a database of the plurality of databases responds to receiving a write request by determining the write request is not creating a parent data record, identifying a parent data record corresponding to the write request, determining a master database of the parent data record, and requesting write approval from the master database of the parent data record.
4 . The computer-implemented method of claim 3 , further comprising responding to write approval from the master database of the parent data record by writing a child data record in the data cluster of the parent data record.
5 . The computer-implemented method of claim 4 , further comprising replicating the data cluster including the child data record to each other database of the plurality of databases.
6 . The computer-implemented method of claim 1 , further comprising responding to a request for write approval from a database of the plurality of databases by comparing a revision number of the data record in the database for which write approval is requested of the data record for which write approval is requested and approving the write request when the revision number of the data record in the database for which write approval is requested is one less than a revision number of the data record in a parent's master database of the data record for which write approval is requested.
7 . The computer-implemented method of claim 1 , wherein the databases in the plurality of databases includes a lock table and the lock table defines the data record undergoing a write operation and defines whether the data record may be written.
8 . The computer-implemented method of claim 7 , wherein the lock table is accessible for the databases in the plurality of databases without requiring access to a correspond parent's master database.
9 . A computer program product comprising:
computer executable instructions for causing a computer system to define a database architecture, the database architecture comprising:
a database system having a plurality of databases, with each database being assigned to a corresponding geographic region, wherein read/write requests originating from a user are assigned to a database in the plurality of databases with the same corresponding geographic region as the user;
the database system defining a schema including defined relationships between data records stored in the database such that each data record stored in the database system is within a data cluster, each data cluster includes a single parent data record, and each data cluster defines a single master database of the plurality of databases, wherein the single master database is the database of the plurality of databases storing the single parent data record; and
replicating a write operation from a database of the plurality of databases to each other database of the plurality of databases by:
determining that the database of the plurality of databases in which the write operation is being replicated from is not a parent's master database of the data record being operated by the write operation;
replicating the write operation to the parent's master database of the data record being operated by the write operation; and
replicating the write operation to each other database in the plurality of databases from the parent's master database of the data record being operated by the write operation.
10 . The computer program product of claim 9 , wherein the single master database corresponding to each data cluster is the database of the plurality of databases assigned to the geographic region from which a write request creating the data cluster originates.
11 . The computer program product of claim 9 , wherein a database of the plurality of databases responds to receiving a write request by determining the write request is not creating a parent data record, identifying a parent data record corresponding to the write request, determining a master database of the parent data record, and requesting write approval from the master database of the parent data record.
12 . The computer program product of claim 11 , further comprising responding to write approval from the master database of the parent data record by writing a child data record in the data cluster of the parent data record.
13 . The computer program product of claim 12 , further comprising replicating the child data record to each other database of the plurality of databases.
14 . The computer program product of claim 9 , further comprising responding to a request for write approval from a database of the plurality of databases by comparing a revision number of the data record in the database for which write approval is requested of the data record for which write approval is requested and approving the write request when the revision number of the data record in the database for which write approval is requested is one less than a revision number of the data record in a parent's master database of the data record for which write approval is requested.
15 . The computer program product of claim 9 , wherein the databases in the plurality of databases includes a lock table and the lock table defines the data record undergoing a write operation and defines whether the data record may be written.
16 . The computer program product of claim 15 , wherein the lock table is accessible for the databases in the plurality of databases without requiring access to a correspond parent's master database.
17 . A computer system comprising:
a database system having a plurality of databases, with each database being assigned to a corresponding geographic region, wherein read/write requests originating from a user are assigned to a database in the plurality of databases with the same corresponding geographic region as the user;
the database system defining a schema including defined relationships between data records stored in the database such that each data record stored in the database system is within a data cluster, each data cluster includes a single parent data record, and each data cluster defines a single master database of the plurality of databases, wherein the single master database is the database of the plurality of databases storing the single parent data record; and
replicating a write operation from a database of the plurality of databases to each other database of the plurality of databases by:
determining that the database of the plurality of databases in which the write operation is being replicated from is not a parent's master database of the data record being operated by the write operation;
replicating the write operation to the parent's master database of the data record being operated by the write operation; and
replicating the write operation to each other database in the plurality of databases from the parent's master database of the data record being operated by the write operation.
18 . The computer system of claim 17 , wherein the single master database corresponding to each data cluster is the database of the plurality of databases assigned to the geographic region from which a write request creating the data cluster originates.