File-backed in-memory structured storage for service synchronization

Providing synchronization to a local system. Embodiments may include downloading a batch of changes in a heterogeneous batch. The batch of changes is correlated to an anchor affiliated with a synchronization service. The anchor is a reference point indicating time or relative order. The batch of changes and the anchor are serialized to a non-volatile storage medium as a heterogeneous set. After serializing the batch of changes to a non-volatile storage medium as a heterogeneous set, entities in the batch of changes are parsed out into entities in in-memory representations. Similarly, embodiments may receive user input modifying a plurality of data entities, store on a non-volatile storage medium a serialized heterogeneous representation of the modified data entities, and upload the serialized heterogeneous representation to a synchronization service.

BACKGROUND

Background and Relevant Art

Further, computing system functionality can be enhanced by a computing system's ability to be interconnected to other computing systems via network connections. Network connections may include, but are not limited to, connections via wired or wireless Ethernet, cellular connections, or even computer to computer connections through serial, parallel, USB, or other connections. The connections allow a computing system to access services at other computing systems and to quickly and efficiently receive application data from other computing systems.

With the interconnection of computer systems comes the ability of different systems to share data. When data is shared, there are often multiple copies of the data, with varying levels of freshness. For example, data may be sent from a first system to a second system, and then immediately changed at the first system. The data at the second system would then be out of date as soon as the changes are made at the first system. Alternatively, data may be sent from a first system to a second system, and then changed at the first system and the second system which would result in there being a conflict as to which data is the freshest.

These issues can be addressed by various synchronization and conflict resolution systems and algorithms. However, some synchronization and conflict resolution systems work at an entity level, such that data must be organized into entities or in-memory representations before synchronization or conflict resolution can occur.

BRIEF SUMMARY

Embodiments may include functionality for providing synchronization to a local system. Embodiments may include downloading a batch of changes in a heterogeneous batch. The batch of changes is correlated to an anchor affiliated with a synchronization service. The anchor is a reference point indicating time or relative order. The batch of changes and the anchor are serialized to a non-volatile storage medium as a heterogeneous set. After serializing the batch of changes to a non-volatile storage medium as a heterogeneous set, entities in the batch of changes are parsed out into entities in in-memory representations. Similarly, embodiments may receive user input modifying a plurality of data entities, store on a non-volatile storage medium a serialized heterogeneous representation of the modified data entities, and upload the serialized heterogeneous representation to a synchronization service.

DETAILED DESCRIPTION

Some embodiments implement an in-memory structured data store that is optimized for synchronization and offline access by serializing heterogeneous batches of changes of entities in the data store to a non-volatile storage medium. Embodiments may implement a structure store built for synchronization in which the data in the store is kept in memory for fast access but also maintained in files to support access to online data when applications are offline. Specifically, some embodiments write different types of files for downloaded incremental batches of changes and local changes, and those files are later read and written to in-memory entity representations. Embodiments may implement a data access layer built on top of these files and a mechanism by which redundant data in files can be cleaned from persistent storage, such as from disk.

Included herein is a description of a mechanism by which incremental sync changes and local changes can be written to disk. This may provide a solution for allowing an interrupted sync to continue while redundant data need not be requested over the network again. Changes saved by the user and by sync may be written as soon as possible to ensure minimal data loss in the event of application termination.

Embodiments may provide entity-based in-memory structured storage that tracks changes for synchronization. Embodiments may also have features directed to approaches by which data is coalesced (i.e. archived) to reduce the amount of redundant data stored on disk.

Referring now toFIG. 1, one embodiment is illustrated. A data store102works by providing in-memory114collections104of entities (each collection104representing a single entity, for example a single data type) designed to work with an anchor-based incremental synchronization service106. A synchronization anchor may be a reference point, such as a reference point in time associated with a change or batch of changes indicating time or relative order changes are applied from the perspective of a synchronization service106. Applications108can retrieve the data from these collections104and perform various CRUD (create, read, update or delete) operations on them. At the same time, the data is persisted to a file system110such as a disk or other persistent or non-volatile storage in a set of files112. Embodiments may be implemented using functionality to persist data to non-volatile storage as soon as possible, to attempt to ensure that no data is lost or needs to be retrieved from the synchronization service106multiple times.

The data store102may perform change tracking on entities and in some embodiments allows for a notion of implicit transactions. A transaction is a set of operations that either all succeed or all fail. If all operations of a transaction succeed, changes to data entities by operations of the transaction are persisted. If a transaction fails, changes to data entities by operations of the transaction are rolled back. Embodiments support implicit transactions by allowing changes to multiple entities to be made before they are saved (if the implicit transaction succeeds) or rolled back (if the implicit transaction fails). Persisted data may be used to roll back operations.

One priority of the data store102may be to persist data to the file system110, such as disk, as soon as it is received from a service106or saved by an application108. To do this, the data store102writes different types of files112that represent different operations on the data store102. One approach for writing data is described below.

In some embodiments, the data store102maintains a monotonically increasing tick count for each file that it writes. The tick count may be, for example, an eight-digit hexadecimal number that is included as part of the file name to ensure that the files are sorted in the order that they are written. When files are read, the file tick count is set to one more than the greatest tick count that was part of a file that was successfully read. Other types of counts or indexes may be alternatively used to order files in the order that they are written. In some embodiments, an underlying file system110allows applications to retrieve information for files such as the last-write time or the creation time. Thus, using the current date time may be used. However this may not be as robust, such as for example when there is a risk that local computer time may be changed. For example a change may be made to an entity, followed by a rolling back of current date and time on the system, followed by a subsequent change to the entity. The subsequent change would be the most current, but this would not be detectable inasmuch as a time stamp associated with the subsequent change would be earlier in time to the first change.

Embodiments may be implemented that employ differentiating file names or extensions. For example, in some embodiments, each type of file that is written will have the specific extension that allows it to be differentiated from other types of files. In particular, as will be discussed in more detail below, some embodiments implement or use six file types: a download file, a local change file, an upload response file, a conflict file, an error file, and/or an archive file. Each of these file types may include a name or extension that helps to differentiate them from each other.

When a batch of changes come from the service106, a download file112is written that contains the entities that were received from the change batch and a synchronization anchor that came with those changes. A synchronization anchor may be a reference point in time for the change batch that where anchors are synchronized from the service106.

When the application108makes changes and saves them, the changes are written to a local change file112. In the illustrated embodiment, this file contains only the entities (e.g. data objects) from the set of changes that was saved as a result of changes by the application108, and not the synchronization anchor, because it was not affiliated with a synchronization service106action. When the application108chooses to save changes, the in-memory114changes are cloned and stored in a separate heterogeneous collection at the file system110. This allows for fast enumeration during synchronization and also protects the data from issues surrounding concurrent access to the data.

When the application108uploads locally saved changes to the service106, the service106will reply with an upload response that contains an updated anchor affiliated with the synchronization service106and information about any conflicts or errors that occurred on the service106. In the event that the service106resolved the conflicts or handled the errors, the data included in the upload response will contain the current versions of the entities as they exist in the service106and the entities that lost the conflict resolution or failed to apply as a result of errors. Inasmuch as resolved conflicts and errors are entirely informational, the data store102may be implemented in some embodiments to allow applications108to clear them one at a time or all together. Thus, in some embodiments, applications may be able to process conflicts and errors individually and quickly without needing to scan an entire dataset. To accommodate this, in some embodiments, each conflict and error is written in its own conflict file112or error file112, respectively. Embodiments may also write an upload to a response file112which contains the current versions of the entities as they exist on the service without the conflict information so that if the conflict/error files are cleared, the updated entities still remain.

Referring now toFIG. 2, a method200is illustrated. The method200illustrates a method of providing synchronization to a local system. The method200includes downloading a batch of changes in a heterogeneous batch (act202). The batch of changes are correlated to an anchor. The anchor is a reference point indicating time or relative order. The anchor may be affiliated with and provided by a synchronization service, such as the synchronization service106.

The method200further includes serializing the batch of changes to a non-volatile storage medium as a heterogeneous set (act204). For example the batch of changes may be stored in a download file112in the file system110.

After serializing the batch of changes to a non-volatile storage medium as a heterogeneous set, the method200further includes parsing out entities in the batch of changes into entities in in-memory representations (act206). For example, entities may be parsed into a collection116. In particular, they may be parsed into separate collections according to their type so that each collection is homogeneous.

The method200may be practiced where the batch of changes in the heterogeneous batch is a delta from a previous in memory representation. In particular, rather than downloading all entities represented in a collection116or collections104, only those entities that have changes since a previous synchronization are downloaded. In some examples of this embodiment, parsing out entities in the batch of changes into entities in in-memory representations may include combining changes in the batch of changes with an existing in-memory representation.

Alternatively, the method200may be practiced wherein parsing out entities in the batch of changes into entities in in-memory representations includes creating a new in-memory representation. This may be performed, for example, when no previous in-memory representations exist for entities in the batch of changes.

The method200may be practiced where serializing the batch of changes to a non-volatile storage medium as a heterogeneous set includes storing the batch of changes to a file system as a single download file that contains all of the entities sent in the batch of changes. In some embodiments, the single download file may include a file name or extension that indicates that the download file is a download file that contains entities sent in a batch of changes. As noted above, this may be used when several different types of files are maintained by the data store to differentiate the different types of files. Similarly, embodiments may be practiced where the single download file includes a file name or extension that includes a tick count representing a relative order position that the download file was written to the non-volatile storage medium. Tick counts are discussed in more detail above.

The method200may be practiced wherein the acts are performed to provide a level of consistency without the use of atomic transactions. Embodiments allows for a notion of implicit transactions. A transaction is a set of operations that either all succeed or all fail. If all operations of a transaction succeed, changes to data entities by operations of the transaction are persisted. If a transaction fails, changes to data entities by operations of the transaction are rolled back. Embodiments support implicit transactions by allowing changes to multiple entities to be made before they are saved (if the implicit transaction succeeds) or rolled back (if the implicit transaction fails). Persisted data may be used to roll back operations.

Referring now toFIG. 3, a method300is illustrated. The method300may be practiced in a computing environment and includes acts for providing synchronization of data entities. The method includes at an application, receiving user input modifying a plurality of data entities (act302). For example, a user interacting with an application108may cause changes to entities stored in a collection116.

The method300further includes storing on a non-volatile storage medium a serialized heterogeneous representation of the modified data entities. For example, a local change file may be stored to the file system100.

The method300further includes uploading the serialized heterogeneous representation to a synchronization service. For example, the changes may be uploaded to the synchronization service106.

As noted above, the method300may be practiced where the serialized heterogeneous representation comprises a single local change file stored in a file system. The method may be practiced where the single local change file includes a file name or extension that indicates that the local change file is a local change file that contains entities sent in a batch of changes. The method300may be practiced where the single local change file includes a file name or extension that includes a tick count representing a relative order position that the local change file was written to the non-volatile storage medium.

The method300may further include receiving an upload response from the synchronization service. The upload response includes an anchor affiliated with the synchronization service and correlated to the serialized heterogeneous representation of the modified data entities. The anchor is a reference point indicating time or relative order from the perspective of the synchronization service. The upload response further includes information about conflicts between entities at the synchronization service and entities in the uploaded serialized heterogeneous representation including current versions of the entities as they exist in the service and entities that lost a conflict resolution or failed to apply as a result of errors. This embodiment of the method may further include retrieving the current entities from the conflict information and storing them in an upload response file along with the anchor affiliated with the synchronization service that was returned. As with other embodiments illustrated herein, the upload response file may be stored to the file system110and may include a file name and/or extension that identifies the file as an upload response file and/or includes an indication of a tick count from the perspective of the data store102.

Embodiments may further include writing each conflict or error in its own conflict file or error file respectively. This can facilitate embodiments where clearing conflicts and/or errors is performed on each conflict or error one at a time. However, alternative embodiments clearing conflicts and/or errors may be performed as a batch.

The above approaches can potentially lead to a great deal of redundant data on the file system110. If an entity is downloaded, modified and saved, and then uploaded with a conflict, there will be three copies of the entity stored on the file system110, despite the fact that only one entity exists in memory114. To mitigate this, the data store102may periodically archive the files112and collapse them into a single archive file112. The algorithm for this, is illustrated as follows:

Embodiments may first retrieve a list of files112stored for the data store102and sorted in reverse order, so that the most recently written files112are written at the front of the list. A dictionary is created to store the entities that have been serialized to the archive file112. The archive anchor is set to null.

A snapshot of the current tick count is obtained, and the tick count is incremented. Any files whose tick count is greater than the snapshot tick count is ignored. This avoids issues with other data store operations occurring during file writing, because they will have a greater tick count.

For each eligible file112(i.e those files with a tick count less than the incremented tick count), at least a portion of the file is read. If the file is not a conflict or error file, then for each entity, if the entity key does not exist in the serialized entities dictionary, the entity is written to the archive file and its key is added to the serialized entity dictionary. The archive anchor will initially be null. If the first files that are read (in reverse order) are saved changes, the anchor will remain null. If a download file, upload response file, or another anchor file is read, the anchor will become non-null. In particular, if the archive anchor is null when a file is read, then the archive anchor becomes the one in that file (if the file contains an anchor). This basically has the effect of making the archive anchor the one from the most recently written file. Additionally, embodiments, may store a flag with each entity in the archive file specifying whether or not it is a local change. This flag will be true for every entity that is read from a local change file until an upload response file is encountered, at which point it will be false for all other local change files. Entities from download and upload response files will always be marked as false.

If all files are read successfully without exceptions, the archive anchor is written to the file and all files are deleted for which the data was included in the archive file.

The data store102reads data in reverse to avoid duplicates in the archive file112and avoid multiple passes on the data. Because this operation is happening on files112that are being read into memory114, rather than on the data that are already in memory114, this can lead to an increase in the process memory that is being used by the data store102. Avoiding multiple passes on the data avoids this by only reading into memory114the amount of data that is in the file system110.

The following illustrates examples of reading data. Embodiments may be implemented where the data store102reads data only once, at the beginning of the process. This ensures that access to data from the application108is fast. Reading the data may be performed as follows and shown inFIG. 4in a method400.FIG. 4illustrates at402an act of Retrieve the list of files for the data store (act402). In some embodiments, the list of files is sorted by file name so that they are read in order. This may be done, for example, by using the tick count as the first part of the file name. For each file112, a determination is made as illustrated at404. If the file112is a conflict or error file, as illustrated at406, it is added to a queue of files to be read when reading the rest of the files is complete (as illustrated at416).

If the file is not a conflict or error file, the entities and anchor from the file are read, if available as illustrated at408. If the file is an archive file, existing in-memory114data is cleared out as illustrated at410Entities are added to in-memory114data an anchor is set as illustrated at412.

As illustrated at416, for each deferred conflict or error file, the conflict or error is read into memory114and its live entity reference is mapped to an in-memory114version of the entity. This may be done so that in-memory entities can be retrieved by the application. In some embodiments, in-memory entities are not updated because the in-memory entities are updated from the upload response file.

Further, upon reaching various computer system components, program code means in the form of computer-executable instructions or data structures can be transferred automatically from transmission computer readable media to physical computer readable storage media (or vice versa). For example, computer-executable instructions or data structures received over a network or data link can be buffered in RAM within a network interface module (e.g., a “NIC”), and then eventually transferred to computer system RAM and/or to less volatile computer readable physical storage media at a computer system. Thus, computer readable physical storage media can be included in computer system components that also (or even primarily) utilize transmission media.