Method and apparatus for storing node
AssigneeTencent Technology (Shenzhen) Company Limited
InventorsChangwen Yuan, Jun Shu
Life of this patent
Estimating the term…
Abstract
The present invention discloses a method and apparatus for storing node, pertaining to the field of the Internet communications. The method includes: receiving a write operation request and a node from a client; storing the node in a memory and setting the update time of the node as the time of receiving the node; and relocating one or more nodes from the memory to a file according to the update time of each of the nodes in the memory. The apparatus includes: a receiving module, a storage module, and a relocating module. The present invention can reduce the frequency of loading and relocating nodes to and from a memory, and improve performance of a server.
Claims15
A method for storing a node, comprising:
- receiving a write operation request and a node from a client;
- storing the node in a memory and setting update time of the node as time of receiving the node;
- and
- relocating one or more nodes from the memory to a file according to update time of each of the nodes in the memory,
- wherein if the node is a child node, the storing the node in a memory and setting update time of the node as time of receiving the node specifically comprises:
- extracting an index of the child node and an index of a root node of the child node from the child node, and storing the extracted indexes in a mapping relationship between indexes of root nodes and indexes of child nodes;
- determining, according to the index of the root node, whether the root node of the child node is stored in the memory;
- if the root node of the child node is stored in the memory, storing the child node in the memory and setting the update time of the node as the time of receiving the child node;
- and
- if the root node of the child node is not stored in the memory, creating a root node of the child node and setting an index of the created root node as the index of the root node, caching the index of the root node in a write event space, storing the child node and the created root node in the memory, and setting both update time of the created root node and update time of the child node as the time of receiving the node.
An apparatus for storing a node, comprising:
- a receiving module, configured to receive a write operation request and a node from a client;
- a storage module, configured to store the node in a memory and setting update time of the node as time of receiving the node;
- and
- a relocating module, configured to relocate one or more nodes from the memory to a file according to update time of each of the nodes in the memory,
- wherein if the node is a child node, the storage module specifically comprises:
- an extracting unit, configured to extract an index of the child node and an index of a root node of the child node from the child node, and store the extracted indexes in a mapping relationship between indexes of root nodes and indexes of child nodes;
- a searching unit, configured to determine, according to the index of the root node, whether the root node of the child node is stored in the memory;
- a setting unit, configured to:
- if the root node of the child node is stored in the memory, store the child node in the memory and set the update time of the node as the time of receiving the child node;
- and
- a storage unit, configured to:
- if the root node of the child node is not stored in the memory, create a root node of the child node and set the index of the created root node as the index of the root node, cache the index of the root node in a write event space, store the child node and the created root node in the memory, and set both the update time of the created root node and the update time of the child node as the time of receiving the node.
Dependencies are inferred from the claim text.