Query Execution
Cursoring and Batching
The CData Virtuality Server cursors all results, regardless of whether they are from one source or many sources, and regardless of what type of processing (joins, unions, etc.) has been performed on the results.
The CData Virtuality Server processes results in batches. A batch is simply a set of records. The number of rows in a batch is determined by the buffer system properties Processor Batch Size (within query engine) and Connector Batch Size (created at connectors).
Client applications have no direct knowledge of batches or batch sizes: they specify the fetch size. However, regardless of the fetch size, the first batch is always proactively returned to synchronous clients. Subsequent batches are returned based on client demand for the data. Pre-fetching is utilized at both the client and connector levels.
Buffer Management
The buffer manager manages memory for all result sets used in the query engine. That includes result sets read from a connection factory, result sets used temporarily during processing, and result sets prepared for a user. Each result set is referred to in the buffer manager as a tuple source.
When retrieving batches from the buffer manager, the batch size in bytes is estimated and then allocated against the max limit.
Memory Management
The buffer manager has two storage managers - a memory manager and a disk manager. The buffer manager maintains the state of all the batches and determines when batches must be moved from memory to disk.
Disk Management
Each tuple source has a dedicated file (named by the ID) on disk. This file will be created only if at least one batch for the tuple source has to be swapped to disk. The file is random access. The connector batch size and processor batch size properties define how many rows can exist in a batch and thus define how granular the batches are when stored in the storage manager. Batches are always read and written from the storage manager whole.
The disk storage manager has a cap on the maximum number of open files to prevent running out of file handles. In cases with heavy buffering, this can cause wait times for a file handle to become available (the default max open files is 64).
Cleanup
When a tuple source is no longer needed, it is removed from the buffer manager. The buffer manager will remove it from both the memory storage manager and the disk storage manager. The disk storage manager will delete the file. In addition, every tuple source is tagged with a "group name", typically the client's session ID. When the client's session is terminated (by closing the connection, server detecting client shutdown, or administrative termination), a call is sent to the buffer manager to remove all tuple sources for the session.
In addition, when the query engine is shut down, the buffer manager is shut down, removing all states from the disk storage manager and causing all files to be closed. When the query engine is stopped, it is safe to delete any files in the buffer directory as they are not used across query engine restarts and must be due to a system crash where buffer files were not cleaned up.