File migration in distributed systems

Methods, apparatuses, and systems for file migration in distributed systems. A data structure definition is added to a programming language source code and initialized. Initialization values include contents of a first data file that is external to the source code file. The source code file is compiled with one or more other source code files to create an executable program that includes the initialization values as part of the program's image. During execution, the executable program creates a different second data file external to the executable program by reading the initialization values from the initialized data structure and writing the values to the second data file. This second data file is accessible by a library linked to the executable program.

TECHNICAL FIELD

The present specification relates to managing files, for example, files in distributed systems.

BACKGROUND

In computing, a distributed file system allows applications executing on a host computer to access files located on separate, remote host computers as though the accessed files are on the host computer. To do so, distributed systems can operate in clusters of computers. When a user accesses the cluster to execute an application, a cluster management system that manages the file system virtualizes the entire cluster as a single machine to the application. The identity of the computer in the cluster that executes the application is typically transparent to the application. The distributed file system dynamically assigns a computer to execute the application. When an application executed by a computer in the cluster requires access to one or more files for execution, the distributed file system makes the file available to the application.

SUMMARY

In general, one innovative aspect of the invention described can be implemented as a method comprising adding, by a data processing apparatus, a data structure definition to a programming language source code file. The method includes an initialization of the definition. Initialization values include contents of a first data file external to the source code file. The initialization values are added to the source code file. The method includes compiling, by the data processing apparatus, the source code file with one or more other source code files to create an executable program that includes the initialization values as part of the executable program's image. During execution, the executable program is configured to create a different second data file external to the executable program by reading the initialization values from the initialized data structure and writing the values to the second data file accessible by a library linked to the executable program.

This, and other aspects, can include one or more of the following features. The method can further include determining that the library depends on the first data file. The executable program can link to the library shooting the execution. The different second data file can be created in a directory local to be working directory of the executable program. The method can further include encoding the initialization values. The method can further include compressing the initialization values. The executable program can include logic to decompress the compressed source code file to create the different data file. The one or more source code files can include logic that caused the executable program to create the different second data file during execution. The method can further include deploying copies of the executable program to multiple computers.

Another innovative aspect of the invention described can be embodied in a computer-readable medium, tangibly embodying software instructions, executed by a data processing apparatus to perform the operations described above. Yet another innovative aspect of the invention described can be embodied in a system including a data processing apparatus and a computer-readable medium encoding software instructions executed by the data processing apparatus to perform the operations described above.

Particular implementations of the subject matter described in this specification can be implemented to realize one or more of the following advantages. Storing a data file as a data structure in an application means the data file is available to the application no matter which computer the application executes on. The data in the application data structure can be encoded or compressed. During execution, the application reads the data in the data structure and writes the data to a local file. This makes the data file available to a library, for example, a third party library, that links to the application and that requires the data file. When the application executes on a different computer, the data file is also available on the different computer because the data file is always part of the executable program. In this manner, the application can easily migrate between different computers in a farm (e.g., if a computer on the farm crashes or becomes unavailable). Alternatively, or in addition, the application can easily migrate from an overloaded computer to a less loaded computer.

The details of one or more implementations of the specification are set forth in the accompanying drawings and the description below. Other features, aspects, and advantages of the specification will become apparent from the description, the drawings, and the claims.

DETAILED DESCRIPTION

FIG. 1shows an example application executing system operating during compile time100and run time105. Compile time105describes an environment in which source code files including computer code, for example, C++ code, are compiled to generate object code files that are linked with the binary to form an executable image. In some implementations, multiple source code files110are compiled by a compiler115into object code files. A data file120is included in addition to the source code files110. The data in the data file120, for example, {1, 2, 3, . . . }, is used by a library that executes an application, as described later. The data file120is transformed into a source code file125that includes an initialization of a data structure definition that represents the data in the data file120. For example, the initialization is represented by “X[ ]={1, 2, 3, . . . };.” The source code file125, obtained by transforming the data file120, is also provided to the compiler115that generates an application130, executable by a file system135, and including a binary image having a representation132of the data in the data file120.

During run time105, a memory145includes the image (data and instructions) required to execute the application130including the data representation132. In some implementations, the memory145includes a code segment150that includes executable instructions. The executable instructions can include a library160of executable instructions configured to be invoked by the application130. The memory145also includes a data segment155including static data (for example, data representation132) representing the global variables that are initialized. When the application130is executed, the data representation132included in the application130is written as a data file140in the file system135, as described later. The application130or its library160can access the data file140from the file system. In this manner, the data file140is available locally to the file system135to execute the application130. In implementations described with reference toFIG. 2, the application130can be executed by multiple computers, for example, in a distributed file system, such that the data is written to each computer when the application is executed, thereby making the data available locally to each computer.

FIG. 2shows an example system200for executing an application. The system200includes a farm205that comprises multiple code processing engines210, for example, code processing engines 1, 2, . . . , n. In some implementations, each code processing engine210is a data processing apparatus, for example, a computer, that is configured to execute applications. In some implementations, the farm205is operatively coupled to a storage medium215, for example, a disk drive or disk array, and an application execution unit220that is configured to cause the code processing engines210to execute the executable program associated with the application execution unit220. In some implementations, the storage medium215can be separate and remote from the farm205. Alternatively, the medium215can be included in the farm205. In some implementations, the storage medium215and the application execution unit220can each be operatively coupled to the farm205through one or more wired or wireless networks112such as the Internet, for example. The system200includes data processing apparatus225operatively coupled to the farm205, the storage medium215, and the application execution unit220, and configured to perform operations described below. In some implementations, the data processing apparatus215can be included along with the code processing engines210in the farm205.

In some implementations, the application execution unit220stores a computer program that is executable by the code processing engines210in the farm. The computer program can be uploaded to the application execution unit220and then transmitted to the farm205through the networks112. In some scenarios, the computer program was written in a programming language such as C++, for example. Other programming languages are possible, however. For execution, the application can require a data structure representing data that is stored in a file on the storage medium215. Specifically, for example, the application can require that the data structure be available on those code processing engines210executing the application. The data processing apparatus225can provide the data structure to such code processing engines210. To do so, the data processing apparatus225can add the data structure definition to the source code of the computer program and also add an initialization of the definition. The initialization values can include contents of the data file storing the data, and can be added to the source code file.

Subsequently, the data processing apparatus225can compile the source code file with one or more other source code files to create an executable program that includes the initialization values as part of the executable program's image. The executable program can be provided to those code processing engines210executing the application, and are executable by each of the code processing engines210. The data processing apparatus225configures the executable program such that, during execution, the executable program creates a different second data file that is external to the executable program. To do so, the code processing engine210executing the executable program reads the initialization values from the initialized data structure and writes the values to the second data file, which is accessible by a library linked to the executable program. In this manner, the data in the data structure is written only to those code processing engines225on which the application executes the executable program.

In some implementations, the computer program is a C++ program. In such implementations, the data processing apparatus225retrieves the data structure, for example, a C++ language data structure, stored in the storage medium215and converts the data file into a byte-array represented by an array of bytes. In this manner, the data processing apparatus225converts the data structure into source code, i.e., the byte-array. Subsequently, the data processing apparatus225compiles the source code into object code and links the object code to form an executable image. Consequently, the data file becomes the data of a executable image and is stored in the memory. When the application execution unit220executes the image, for example, on those code processing engines210executing the application, then the application execution unit220reads the binary image because the byte array is an array of bytes in the data segment of memory.

Once the application execution unit220reads the binary image, the unit220can create a temporary local file in the code processing engine210in which the application is executing. For example, if 100 code processing engines210are executing the application, then the application execution unit220will read the array of bytes in the data segment of the memory of each of the code processing engines210, and will write the contents of the memory on each engine210. By doing so, the temporary local file can be created and stored in each of the code processing engines210. In some implementations, the temporary local file created on each code processing engine210can be given a file name that can be provided to a third party library. Using the file name, the third party library can access the temporary local file. Details of the techniques using which the temporary local file is created are described with reference toFIG. 2.

FIG. 2shows an example system to execute an application in a distributed file system. As described previously, the application execution unit220stores an application that is executable by one or more of the code processing engines210in the farm205. To do so, the application execution unit220requires data in a file that is stored in the storage medium215. To create a temporary local file that contains the required data in those code processing engines210that execute the application, the data processing apparatus225retrieves the data file. In some implementations, the data processing apparatus225will read the data file from the storage medium215and generate a source code file, for example, a “.cc” file. The generated “.cc” file includes an array of characters, each of which represents the data that is required by the application. For example, the data processing apparatus225reads out the data stored in the file, puts the read-out data into an array structure for C++, stores the array structure in a C++ file, and compiles the array structure as static data. For example, the data processing apparatus225creates a 1000 byte data structure in source file that contains the array of characters, each of which corresponds to content in the data file.

Upon creation, the data processing apparatus225gives the source code file a name, for example, a name based on the naming conventions of C++ source code files. The data processing apparatus225then compiles the source code file into a separate object code file, for example, an object code file having a “.o” file name. The data processing apparatus225then links the “.o” file to the binary and gives the array name to the executable, i.e., the computer program executed on the code processing engines210. The program uses the array name to reference the array and to read the data bytes stored within. Thus, the data processing apparatus225takes an ordinary text file and generates a source code file, for example, a C++ file, that contains the data as an array of bytes. Consequently, the text file that is needed for the application to execute is converted to source code. Subsequent to compiling, object code generation, and linking to the executable image, when the program executes the image, the byte array is read from the image and written to storage.

In some implementations, the compiling operations can be performed by a compiler305included in each code processing engine210. The code processing engines210can each include an execution unit310to execute the computer program and storage315to store the temporary local file and other data. Each execution unit310generates a temporary local file including the contents of the data file stored in the storage medium215, and stores the temporary local file in the storage315. The instructions to read out the data in the storage medium215and store the data as an array structure also includes instructions to write the data to a directory that is local to a working directory of the executing program in the storage315. The processes performed by the system200are described with reference toFIG. 3

FIG. 3shows a flowchart of an example process400to execute an application in a farm of computers. The process400adds a data structure definition to a source code file, for example, a C++ source code file at405. The process400adds an initialization of the definition that includes contents of a first data file external to the source code file at410. Further, the process400adds the initialization values to the source code file. In some implementations, the process400checks if compressing the source code file, for example, the byte array, is required at415. For example, if the size of the data structure definition or the first data file or both is so large that compiling the source code file is time and/or resource intensive, for example, because the object file containing the data takes too much memory, then the source code file may need to be compressed. In such implementations, if the process400determines that compression is required, then process400compresses the source code at420. In some implementations, the process400checks if transcoding is required at425. If the data structure definition or the data in the first data file is encoded in a scheme that is different from the encoding scheme of the source code file, then the code of the data structure definition or the data in the first data file may need to be changed, i.e., transcoded, into that of the source code file. For example, Chinese characters have a different encoding scheme than English characters. Chinese third party applications may require data including English content. In such scenarios, the encoding of the English content can be changed from English to Unicode Transformation Format (UTF) prior to compiling. In such implementations, if the process400determines that transcoding is required, then process400transcodes the data structure definition or the first data file, as required at430. By transcoding the data file into the byte array in the source code, the process400can transcode to interface between the two types of encoding schemes.

The process400compiles the source code file with other source code files to create an executable program at435. The process400executes the executable program at440. Alternatively, the executable program can be executed by another process, for example, one executed by an application execution unit220. Executing the process creates a different second data file external to the executable program at445. The process400determines that a library needs the first data file450. In response, the process400links the executable program to the library during execution at455, for example, by passing the path of the second data file to the library.

Thus, particular embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In certain implementations, multitasking and parallel processing may be advantageous. In some implementations, more than one data file can be required for the application to execute. In such implementations, multiple data structure definitions can be added to the source code file. Also, corresponding initializations of the definition that includes contents of the data files can be added to the source code file. Upon compilation, the binary image can include multiple byte arrays, each representing a data file. In some scenarios, the data file that is converted into a byte-array and compiled with the source code file is not located at the beginning of the “.cc” file obtained by compiling, but is rather offset from the beginning. In such scenarios, the data processing apparatus225can be configured to create an offset to read the byte-array from any position in the “.cc” file, specifically, for example, the offset position. In some implementations, a header file and object code can be generated by compiling. The header file can include the name of the data file using which the compiled data file can be added to the binary image. In some implementations, the source files can be generated by a script.