The final close of a c-tree file causes all existing file contents (data records or index nodes) to be flushed from cache to disk. A final close refers to a file close that causes the user count of the file to drop to zero. For applications opening and closing files during operation, it is often times advantageous for a file to remain cached for best performance. Many applications simply open a file at startup within a "private" c-tree connection and then close the file at application end.
It is possible to have the file's data persist in cache even after a final close by including ctKEEPOPEN bit in the splval member of the data file’s XCREblk. In this case, the final close leaves the file open (without any user attached to the file) and any cached data will be retained. When the file is again reopened, the data is immediately available for use saving expensive I/O time reloading data and index cache pages. This frees the application from having to maintain any state knowledge of the file.
The file is always closed when the server terminates protecting any data in cache. To force a ctKEEPOPEN file close, call the CloseCtFileByName() c-tree API function:
CloseCtFileByName(pTEXT filnam, pTEXT fileword)
It is possible to use the ctKEEPOPEN flag on the create, and then close and reopen the file shared, but only if the file’s creation is not pending commit. In this case, the sequence would be like:
XCREblk xcreblk[] = {
{ctMEMFILE, 0, 0, 104857600, 0,0,0,0,0,0, ctKEEPOPEN, 0,0,0,0,0},
{ctMEMFILE, 0, 0, 104857600, 0,0,0,0,0,0, ctKEEPOPEN, 0,0,0,0,0}
};
if (CreateIFileXtd8(&vcustomer,NULL,NULL,0,NULL,NULL,xcreblk))
{
ctrt_printf("\nCould not create file %d with error %d.\n",
isam_fil,isam_err);
}
else
{
CloseIFile(&vcustomer);
if ((eRet = OpenIFileXtd(&vcustomer,NULL,NULL,NULL)) != 0)
{
ctrt_printf("\nUNEXPECTED ERROR %d ON REOPEN.\n",eRet);
}
else
{
ctrt_printf("\nFile created.");
}
}