





技术领域technical field
本发明涉及互联网技术领域,尤其涉及一种数据存储方法和装置。The present invention relates to the field of Internet technologies, and in particular, to a data storage method and device.
背景技术Background technique
目前,在互联网领域广泛使用的基于内存的KeyValue存储,主要有Memcache,Redis等;Memcache是一个自由、源码开放、高性能、分布式的分布式内存对象缓存系统;Redis是一个使用ANSI C编写的开源、包含多种数据结构、支持网络、基于内存、可选持久性的键值对存储数据库;这些存储一般情况下都将数据存储在自身申请的内存当中,并通过网络协议对外提供服务,相对一些基于磁盘的数据库而言,这些基于内存的数据库性能非常高。Memcache和Redis数据库提供服务的方式主要是通过网络,本身监听一个网络端口,其他应用程序通过网络访问数据库,由此带来的一个问题是,即使其他应用程序和数据库本身在同一台机器上,仍然需要通过本地的网络协议栈来访问数据库,消耗比较大,效率比较低。而且Memcache数据库也没有持久化特性,如果数据库本身重启,或者机器出现问题而重启,会导致原有存储的数据丢失,从而影响其他应用程序的正常运行。At present, the memory-based KeyValue storage widely used in the Internet field mainly includes Memcache, Redis, etc. Memcache is a free, open source, high-performance, distributed distributed memory object caching system; Redis is a system written in ANSI C. Open source, including a variety of data structures, supporting the network, memory-based, optional persistence key-value pair storage database; these storages generally store data in the memory they apply for, and provide external services through network protocols, relatively For some disk-based databases, these memory-based databases are very performant. The way Memcache and Redis databases provide services is mainly through the network. They listen to a network port, and other applications access the database through the network. One problem is that even if other applications and the database are on the same machine, they still It is necessary to access the database through the local network protocol stack, which consumes a lot of money and has low efficiency. Moreover, the Memcache database has no persistence feature. If the database itself restarts, or the machine restarts due to a problem, the original stored data will be lost, thereby affecting the normal operation of other applications.
在实现本发明过程中,申请人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the applicant found that there are at least the following problems in the prior art:
当基于网络协议的数据库同时支持本地应用和远程应用的访问时,本地应用对基于网络协议的数据库的访问,消耗比较大,效率比较低。When a network protocol-based database supports both local application and remote application access, the local application's access to the network protocol-based database is relatively expensive and inefficient.
发明内容SUMMARY OF THE INVENTION
本发明实施例提供一种数据存储方法和装置,解决了当基于网络协议的数据库同时支持本地应用和远程应用的访问时,本地应用对基于网络协议的数据库的访问,消耗比较大,效率比较低的问题。The embodiments of the present invention provide a data storage method and device, which solves the problem that when a network protocol-based database supports both local application and remote application access, the local application's access to the network protocol-based database is relatively large in consumption and low in efficiency. The problem.
为达上述目的,一方面,本发明实施例提供一种数据存储方法,包括:In order to achieve the above purpose, on the one hand, an embodiment of the present invention provides a data storage method, including:
响应于收到的按指定网络协议读写指定格式的存储数据的远程读写请求,调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;In response to a received remote read and write request for reading and writing stored data in a specified format according to a specified network protocol, calling a pre-implemented local read-write interface to read or write the stored data in the shared memory according to the specified format;
响应于收到的读写所述指定格式的存储数据的本地读写请求,调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;In response to the received local read and write request for reading and writing the storage data in the specified format, calling a pre-implemented local read-write interface to read or write the storage data in the shared memory according to the specified format;
所述共享内存是在本地系统中分配的用于一个或多个进程以共享的方式读写数据的内存。The shared memory is memory allocated in the local system for one or more processes to read and write data in a shared manner.
进一步地,还包括:Further, it also includes:
在收到所述远程读写请求或所述本地读写请求后,在共享内存中读取或写入所述存储数据之前,判断所述共享内存是否已经分配;After receiving the remote read/write request or the local read/write request, before reading or writing the stored data in the shared memory, determine whether the shared memory has been allocated;
如果判断出所述共享内存没有分配,则根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存;If it is judged that the shared memory is not allocated, then allocate the shared memory in the local system according to the pre-specified size of the shared memory; and format the shared memory according to the specified formatting rule;
如果判断出所述共享内存已经分配,则获取通过校验的所述共享内存。If it is determined that the shared memory has been allocated, the shared memory that has passed the verification is acquired.
进一步地,所述共享内存包括头部内存和至少一个存储区;Further, the shared memory includes a header memory and at least one storage area;
根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存,包括:Allocate the shared memory in the local system according to the pre-specified size of the shared memory; and format the shared memory according to a specified format rule, including:
在本地系统中按所述共享内存的大小分配所述共享内存;Allocate the shared memory in the local system according to the size of the shared memory;
根据预先指定的所有存储区所占用空间的起始地址和终止地址、每个存储区各自的扇区数和扇区大小决定因子,计算可划分出的存储区数量;Calculate the number of storage areas that can be divided according to the pre-specified start and end addresses of the space occupied by all storage areas, the number of sectors in each storage area and the sector size determination factor;
根据所述共享内存的头部内存需要保存的头部信息和所述存储区数量,计算出需要保留的头部内存的大小;将所述共享内存划分为所述头部内存和所述至少一个存储区;其中,所述头部信息包括:共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和指定数组长度的木桶数组;Calculate the size of the header memory to be reserved according to the header information to be saved in the header memory of the shared memory and the number of storage areas; divide the shared memory into the header memory and the at least one Storage area; wherein, the header information includes: the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, the starting address of the sector linked list corresponding to each storage area and the specified array length. cask array;
将每个存储区按该存储区的特定扇区字节数格式化为至少一个扇区;其中,各存储区对应的特定扇区字节数根据扇区大小决定因子得到;Each storage area is formatted into at least one sector according to the specific sector byte number of the storage area; wherein, the specific sector byte number corresponding to each storage area is obtained according to the sector size determination factor;
针对每个存储区,将该存储区中的所有扇区的地址以链表方式保存在与该存储区对应的链表中,将该链表作为该存储区对应的扇区链表;For each storage area, the addresses of all sectors in the storage area are stored in the linked list corresponding to the storage area in a linked list, and the linked list is used as the sector linked list corresponding to the storage area;
将所述共享内存的版本、所述头部内存的大小、所述共享内存的大小、所述读写锁、各存储区各自对应的扇区链表的起始地址和设置为空的所述木桶数组保存在所述头部内存中;The version of the shared memory, the size of the head memory, the size of the shared memory, the read-write lock, the starting address of the sector linked list corresponding to each storage area and the wood set to be empty. The bucket array is stored in the header memory;
所述获取通过校验的所述共享内存,包括:The obtaining of the shared memory that has passed the verification includes:
打开本地系统中已经分配的所述共享内存;open the shared memory that has been allocated in the local system;
从所述头部内存中读取所述共享内存的版本;read a version of the shared memory from the header memory;
将所述共享内存的版本与指定内存版本比较,如果所述共享内存的版本兼容所述指定内存版本,则返回共享内存可用的信息并获取所述共享内存;Compare the version of the shared memory with the specified memory version, and if the version of the shared memory is compatible with the specified memory version, return the information that the shared memory is available and obtain the shared memory;
其中,所述木桶数组的每个数组元素用于保存由已经写入指定格式的数据的扇区构成的链表的起始地址。Wherein, each array element of the bucket array is used to store the starting address of the linked list formed by the sectors in which the data of the specified format has been written.
进一步地,所述指定网络协议包括Memcache协议和Redis协议;Further, the specified network protocol includes Memcache protocol and Redis protocol;
所述指定格式包括键字符串和取值;The specified format includes a key string and a value;
所述调用预先实现的本地读写接口按所述指定格式在共享内存中读取或设置所述存储数据,包括:The calling of the pre-implemented local read/write interface reads or sets the stored data in the shared memory according to the specified format, including:
使用哈希算法将所述存储数据中的所述键字符串转换成哈希值;将所述哈希值除以所述木桶数组的长度,获取余数;Convert the key string in the stored data into a hash value using a hash algorithm; divide the hash value by the length of the bucket array to obtain the remainder;
如果调用本地读写接口的读取操作,则针对所述共享内存加读锁,找到所述木桶数组中第所述余数位置处的数组元素保存的链表的起始地址,将找到的链表作为待遍历链表;遍历所述待遍历链表的元素,如果发现某个元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回该元素对应的扇区中记录的取值;如果没有发现任何元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回键字符串不存在的错误信息;If the read operation of the local read-write interface is invoked, a read lock is added to the shared memory, and the starting address of the linked list stored by the array element at the remainder position in the bucket array is found, and the found linked list is used as The linked list to be traversed; the elements of the linked list to be traversed are traversed, if it is found that the key string recorded in the sector corresponding to a certain element is the same as the key string corresponding to the stored data, then the record in the sector corresponding to the element is returned If it is not found that the key string recorded in the sector corresponding to any element is the same as the key string corresponding to the stored data, the error message that the key string does not exist is returned;
如果调用本地读写接口的写入操作,则针对所述共享内存加写锁,并计算所述存储数据的键字符串和取值的总占用空间长度;将所述总占用空间长度与每个存储区的特定扇区字节数比较,确定保存所述存储数据所需的最小特定扇区字节数;在所述最小特定扇区字节数对应的存储区对应的扇区链表中查找一个空闲扇区,如果没有找到任何空闲扇区,则返回无可用内存的错误信息,如果找到空闲扇区则将所述存储数据的键字符串和取值复制到该空闲扇区,将该空闲扇区添加到所述木桶数组中第所述余数位置处的数组元素保存的链表中,并将该空闲扇区标识为已用。If the write operation of the local read-write interface is invoked, a write lock is added to the shared memory, and the total occupied space length of the key string and value of the stored data is calculated; the total occupied space length and each Compare the number of bytes in a specific sector of the storage area, and determine the minimum number of bytes in a specific sector required to save the stored data; search for a sector linked list corresponding to the storage area corresponding to the minimum number of bytes in a specific sector Free sector, if no free sector is found, an error message of no available memory is returned. If a free sector is found, the key string and value of the stored data are copied to the free sector, and the free sector The area is added to the linked list saved by the array element at the remainder position in the bucket array, and the free sector is marked as used.
进一步地,还包括:Further, it also includes:
根据指定持久化规则,调用本地读写接口将所述共享内存中的指定格式的数据持久化到持久存储装置中;并且在重新启动时,从所述持久存储装置中加载是所述指定格式的数据到所述共享内存。According to the specified persistence rule, the local read-write interface is called to persist the data in the specified format in the shared memory to the persistent storage device; and when restarting, the data in the specified format is loaded from the persistent storage device. data into the shared memory.
另一方面,本发明实施例提供一种数据存储装置,包括:On the other hand, an embodiment of the present invention provides a data storage device, including:
网络读写单元,用于响应于收到的按指定网络协议读写指定格式的存储数据的远程读写请求,触发本地读写模块完成调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;The network read-write unit is used to trigger the local read-write module to complete the call of the pre-implemented local read-write interface according to the specified format in response to the received remote read-write request for reading and writing the stored data in the specified format according to the specified network protocol. read or write the stored data in memory;
本地读写单元,用于响应于收到的读写所述指定格式的存储数据的本地读写请求,触发所述本地读写模块完成调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;The local read-write unit is used to trigger the local read-write module to complete the invocation of the pre-implemented local read-write interface according to the specified format in response to the received local read-write request for reading and writing the stored data in the specified format. read or write the stored data in memory;
所述共享内存是在本地系统中分配的用于一个或多个进程以共享的方式读写数据的内存。The shared memory is memory allocated in the local system for one or more processes to read and write data in a shared manner.
进一步地,还包括:Further, it also includes:
内存检测单元,用于在收到所述远程读写请求或所述本地读写请求后,在共享内存中读取或写入所述存储数据之前,判断所述共享内存是否已经分配;a memory detection unit, configured to determine whether the shared memory has been allocated before reading or writing the stored data in the shared memory after receiving the remote read/write request or the local read/write request;
内存创建单元,用于如果判断出所述共享内存没有分配,则根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存;A memory creation unit, configured to allocate the shared memory in the local system according to the pre-specified size of the shared memory if it is judged that the shared memory is not allocated; and format the shared memory according to a specified formatting rule;
内存获取单元,用于如果判断出所述共享内存已经分配,则获取通过校验的所述共享内存。A memory acquisition unit, configured to acquire the shared memory that has passed the verification if it is determined that the shared memory has been allocated.
进一步地,所述共享内存包括头部内存和至少一个存储区;Further, the shared memory includes a header memory and at least one storage area;
所述内存创建单元,包括:The memory creation unit includes:
共享内存分配模块,用于在本地系统中按所述共享内存的大小分配所述共享内存;a shared memory allocation module, configured to allocate the shared memory in the local system according to the size of the shared memory;
存储区数量规划模块,用于根据预先指定的所有存储区所占用空间的起始地址和终止地址、每个存储区各自的扇区数和扇区大小决定因子,计算出可划分出的存储区数量;The storage area quantity planning module is used to calculate the storage area that can be divided according to the pre-specified starting address and ending address of the space occupied by all storage areas, the number of sectors and sector size determination factors of each storage area. quantity;
第一格式化模块,用于根据所述共享内存的头部内存需要保存的头部信息和所述存储区数量,计算出需要保留的头部内存的大小;将所述共享内存划分为所述头部内存和所述至少一个存储区;其中,所述头部信息包括:共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和指定数组长度的木桶数组;The first formatting module is used to calculate the size of the header memory that needs to be reserved according to the header information that needs to be saved in the header memory of the shared memory and the number of storage areas; the shared memory is divided into the The header memory and the at least one storage area; wherein, the header information includes: the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, and the corresponding sector list of each storage area. The starting address and the array of barrels with the specified array length;
第二格式化模块,用于将每个存储区按该存储区的特定扇区字节数格式化为至少一个扇区;其中,各存储区对应的特定扇区字节数根据扇区大小决定因子得到;The second formatting module is used to format each storage area into at least one sector according to the number of bytes of the specific sector of the storage area; wherein, the number of bytes of the specific sector corresponding to each storage area is determined according to the size of the sector factor is obtained;
第三格式化模块,用于针对每个存储区,将该存储区中的所有扇区的地址以链表方式保存在与该存储区对应的链表中,将该链表作为该存储区对应的扇区链表;The third formatting module is used for, for each storage area, the addresses of all sectors in the storage area are stored in the linked list corresponding to the storage area in a linked list, and the linked list is used as the sector corresponding to the storage area linked list;
第四格式化模块,用于将所述共享内存的版本、所述头部内存的大小、所述共享内存的大小、所述读写锁、各存储区各自对应的扇区链表的起始地址和设置为空的所述木桶数组保存在所述头部内存中;The fourth formatting module is used to format the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, and the starting address of the sector linked list corresponding to each storage area. and the bucket array set to empty is stored in the header memory;
所述内存获取单元,具体配置为:打开本地系统中已经分配的所述共享内存;从所述头部内存中读取所述共享内存的版本;将所述共享内存的版本与指定内存版本比较,如果所述共享内存的版本兼容所述指定内存版本,则返回共享内存可用的信息并获取所述共享内存;The memory acquisition unit is specifically configured to: open the shared memory that has been allocated in the local system; read the version of the shared memory from the head memory; compare the version of the shared memory with the specified memory version , if the version of the shared memory is compatible with the specified memory version, return the information that the shared memory is available and obtain the shared memory;
其中,所述木桶数组的每个数组元素用于保存由已经写入指定格式的数据的扇区构成的链表的起始地址。Wherein, each array element of the bucket array is used to store the starting address of the linked list formed by the sectors in which the data of the specified format has been written.
进一步地,所述指定网络协议包括Memcache协议和Redis协议;Further, the specified network protocol includes Memcache protocol and Redis protocol;
所述指定格式包括键字符串和取值;The specified format includes a key string and a value;
所述本地读写模块,包括:The local read-write module includes:
读写位置获取模块,用于使用哈希算法将所述存储数据中的所述键字符串转换成哈希值;将所述哈希值除以所述木桶数组的长度,获取余数;a read-write position acquisition module, used to convert the key string in the stored data into a hash value using a hash algorithm; divide the hash value by the length of the bucket array to obtain the remainder;
读取模块,用于如果调用本地读写接口的读取操作,则针对所述共享内存加读锁,找到所述木桶数组中第所述余数位置处的数组元素保存的链表的起始地址,将找到的链表作为待遍历链表;遍历所述待遍历链表的元素,如果发现某个元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回该元素对应的扇区中记录的取值;如果没有发现任何元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回键字符串不存在的错误信息;The reading module is used to add a read lock to the shared memory if the read operation of the local read-write interface is called, and find the starting address of the linked list stored by the array element at the remainder position in the bucket array , take the found linked list as the linked list to be traversed; traverse the elements of the linked list to be traversed, if it is found that the key string recorded in the sector corresponding to a certain element is the same as the key string corresponding to the stored data, then return the element The value recorded in the corresponding sector; if it is not found that the key character string recorded in the sector corresponding to any element is the same as the key character string corresponding to the stored data, the error message that the key character string does not exist is returned;
写入模块,用于如果调用本地读写接口的写入操作,则针对所述共享内存加写锁,并计算所述存储数据的键字符串和取值的总占用空间长度;将所述总占用空间长度与每个存储区的特定扇区字节数比较,确定保存所述存储数据所需的最小特定扇区字节数;在所述最小特定扇区字节数对应的存储区对应的扇区链表中查找一个空闲扇区,如果没有找到任何空闲扇区,则返回无可用内存的错误信息,如果找到空闲扇区则将所述存储数据的键字符串和取值复制到该空闲扇区,将该空闲扇区添加到所述木桶数组中第所述余数位置处的数组元素保存的链表中,并将该空闲扇区标识为已用。The writing module is used to add a write lock to the shared memory if the write operation of the local read-write interface is called, and calculate the total occupied space length of the key string and the value of the stored data; The length of the occupied space is compared with the number of bytes of a specific sector of each storage area to determine the minimum number of bytes of a specific sector required to save the storage data; Find a free sector in the sector linked list, if no free sector is found, return the error message of no available memory, if a free sector is found, copy the key string and value of the stored data to the free sector area, add the free sector to the linked list saved by the array element at the remainder position in the bucket array, and mark the free sector as used.
进一步地,还包括:Further, it also includes:
持久化单元,用于根据指定持久化规则,调用本地读写接口将所述共享内存中的指定格式的数据持久化到持久存储装置中;并且在重新启动时,从所述持久存储装置中加载所述指定格式的数据到所述共享内存。A persistence unit, configured to call the local read-write interface to persist the data in the specified format in the shared memory to the persistent storage device according to the specified persistence rule; and when restarting, load from the persistent storage device The data in the specified format is transferred to the shared memory.
上述技术方案具有如下有益效果:通过使用共享内存并提供读写共享内存的本地读写接口允许本地应用程序绕过网络协议栈,直接与基于共享内存的数据库对应的内存区域进行交互,从而获得极高的性能,同时可兼容指定网络协议的远程读写请求。通过共享内存的机制,基于同一个共享内存实现的数据存储可以同时被多个本地应用程序和组件共享,也支持通过指定网络协议被多个外部用户远程访问。进一步地,通过按指定持久化规则将数据持久化,即使在机器重启的情况下也可以保证数据不会丢失。The above technical solution has the following beneficial effects: by using the shared memory and providing a local read and write interface for reading and writing the shared memory, the local application program can bypass the network protocol stack and directly interact with the memory area corresponding to the shared memory-based database, thereby obtaining extremely high performance. High performance and compatible with remote read and write requests of specified network protocols. Through the shared memory mechanism, data storage based on the same shared memory can be shared by multiple local applications and components at the same time, and also supports remote access by multiple external users through a specified network protocol. Further, by persisting the data according to the specified persistence rules, it is guaranteed that the data will not be lost even when the machine is restarted.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the embodiments of the present invention or the technical solutions in the prior art more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained according to these drawings without creative efforts.
图1是本发明实施例之一的一种数据存储方法的流程图;1 is a flowchart of a data storage method according to one of the embodiments of the present invention;
图2是本发明实施例之一通过远程读写请求访问共享内存的一种流程图;Fig. 2 is a kind of flow chart of accessing shared memory through remote read-write request according to one of the embodiments of the present invention;
图3是本发明实施例之一在本地直接通过本地读写接口访问共享内存的一种流程图;Fig. 3 is a kind of flow chart that one of the embodiments of the present invention directly accesses shared memory locally through a local read-write interface;
图4是本发明实施例之一的本地读写单元、网络读写单元、持久化单元和共享内存之间的数据流向示意图;4 is a schematic diagram of a data flow between a local read-write unit, a network read-write unit, a persistence unit and a shared memory in one embodiment of the present invention;
图5是本发明实施例之一的持久化过程的一种流程图;Fig. 5 is a kind of flow chart of the persistence process of one of the embodiments of the present invention;
图6是本发明实施例之一的一种数据存储装置的结构示意图。FIG. 6 is a schematic structural diagram of a data storage device according to an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
一方面,如图1所示,本发明实施例提供一种数据存储方法,包括:On the one hand, as shown in FIG. 1 , an embodiment of the present invention provides a data storage method, including:
步骤S100,如图2所示,响应于收到的按指定网络协议读写指定格式的存储数据的远程读写请求,调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;Step S100, as shown in Figure 2, in response to the received remote read and write request for reading and writing stored data in a specified format according to a specified network protocol, calling a pre-implemented local read and write interface to read in the shared memory according to the specified format. or write said stored data;
步骤S101,如图3所示,响应于收到的读写所述指定格式的存储数据的本地读写请求,调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;Step S101, as shown in Figure 3, in response to the received local read and write request for reading and writing the storage data in the specified format, calling a pre-implemented local read-write interface to read or write in the shared memory according to the specified format. into the stored data;
所述共享内存是在本地系统中分配的用于一个或多个进程以共享的方式读写数据的内存。The shared memory is memory allocated in the local system for one or more processes to read and write data in a shared manner.
在一些实施例中,通过调用本地系统调用或自定义的本地共享内存分配以及获取接口,在本地内存中分配新的共享内存或者获取已经分配的共享内存的句柄,从而为后续步骤访问共享内存做准备。实现共享内存的具体方法有多种,可根据具体需要以及具体的系统进行选择,例如linux系统中包括但不限于通过mmap内存共享映射、XSI共享内存或POSIX共享内存等;预先实现的本地读写接口用于通过本地系统调用或自定义的本地共享内存操作接口对共享内存进行读写操作,实现读写指定格式的存储数据。保存于共享内存中的数据的指定格式可根据具体需求确定,例如指定格式包括但不限于KeyValue(即键字符串和取值)对格式的数据或者根据需求自定义的二进制格式的数据等。当接收到远程读写请求后,将远程读写请求对应转换为对本地读写接口的调用。远程读写请求用于通过网络接口与本地的共享内存中的数据进行通信;远程读写请求可以来自互联网上的另一台计算设备上的应用;与共享内存在同一计算设备上的应用可根据具体需要选择通过指定网络协议的远程读写请求操作本地的共享内存中的数据,也可以优选地直接通过本地读写接口直接操作本地的共享内存中的数据。在具体实施部署时,如图4所示,预先将本地读写接口封装为本地接口库模块,本地接口库模块用于支持本地应用程序(即本地读写单元)直接操作共享内存,也用于支持网络接口模块(即网络读写单元)将远程读写请求转换为对本地读写接口的调用后读写共享内存,预先将处理按指定网络协议读写对应的指定格式的存储数据的远程读写请求的过程封装为网络接口模块,远程应用或希望通过指定网络协议访问共享内存中的数据的本地应用可以通过网络接口模块访问共享内存中的数据;希望高效操作共享内存中的数据的本地应用则可以直接通过本地接口库模块访问共享内存中的数据。通过共享内存机制,可以同时为一个或多个远程应用和/或一个或多个本地应用提供同一共享内存的数据服务。指定网络协议包括但不限于Memcache和Redis协议。In some embodiments, by calling a local system call or a custom local shared memory allocation and acquisition interface, a new shared memory is allocated in the local memory or a handle of the allocated shared memory is obtained, so as to access the shared memory for subsequent steps. Prepare. There are many specific methods for realizing shared memory, which can be selected according to specific needs and specific systems. For example, in the Linux system, including but not limited to memory shared mapping through mmap, XSI shared memory or POSIX shared memory, etc.; pre-implemented local read and write The interface is used to perform read and write operations on shared memory through local system calls or customized local shared memory operation interfaces, so as to read and write stored data in a specified format. The specified format of the data stored in the shared memory can be determined according to specific requirements. For example, the specified format includes, but is not limited to, data in KeyValue (ie, key string and value) pair format or data in binary format customized according to requirements. When a remote read/write request is received, the remote read/write request is correspondingly converted into a call to the local read/write interface. Remote read and write requests are used to communicate with data in the local shared memory through a network interface; remote read and write requests can come from applications on another computing device on the Internet; applications on the same computing device as shared memory can be based on Specifically, it is necessary to choose to operate the data in the local shared memory through a remote read and write request of a specified network protocol, or preferably directly operate the data in the local shared memory directly through the local read and write interface. In the specific implementation and deployment, as shown in Figure 4, the local read-write interface is encapsulated as a local interface library module in advance. Support the network interface module (ie network read/write unit) to convert the remote read/write request into a call to the local read/write interface to read and write the shared memory, and pre-process the remote read of the stored data in the specified format according to the specified network protocol. The process of write request is encapsulated as a network interface module. Remote applications or local applications that wish to access data in shared memory through a specified network protocol can access data in shared memory through the network interface module; local applications that wish to efficiently operate data in shared memory Then the data in the shared memory can be accessed directly through the local interface library module. Through the shared memory mechanism, one or more remote applications and/or one or more local applications can be provided with data services of the same shared memory at the same time. Specified network protocols include but are not limited to Memcache and Redis protocols.
本发明实施例具有如下技术效果:通过使用共享内存并提供读写共享内存的本地读写接口允许本地应用程序绕过网络协议栈,直接与基于共享内存的数据库对应的内存区域进行交互,从而获得极高的性能,同时可兼容指定网络协议的远程读写请求。通过共享内存的机制,基于同一个共享内存实现的数据存储可以同时被多个本地应用程序和组件共享,也支持通过指定网络协议被多个外部用户远程访问。通过对Memcache和Redis协议的兼容,本实施例可无缝替换当前项目中已经使用的Memcache或Redis组件,达到以最小的修改成本提高本地应用的数据读写效率的效果。The embodiments of the present invention have the following technical effects: by using the shared memory and providing a local read-write interface for reading and writing the shared memory, the local application program can bypass the network protocol stack and directly interact with the memory area corresponding to the shared memory-based database, thereby obtaining Extremely high performance, and compatible with remote read and write requests of specified network protocols. Through the shared memory mechanism, data storage based on the same shared memory can be shared by multiple local applications and components at the same time, and also supports remote access by multiple external users through a specified network protocol. Through the compatibility of the Memcache and Redis protocols, this embodiment can seamlessly replace the Memcache or Redis components already used in the current project, so as to achieve the effect of improving the data reading and writing efficiency of the local application with the minimum modification cost.
进一步地,还包括:Further, it also includes:
在收到所述远程读写请求或所述本地读写请求后,在共享内存中读取或写入所述存储数据之前,判断所述共享内存是否已经分配;After receiving the remote read/write request or the local read/write request, before reading or writing the stored data in the shared memory, determine whether the shared memory has been allocated;
如果判断出所述共享内存没有分配,则根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存;If it is judged that the shared memory is not allocated, then allocate the shared memory in the local system according to the pre-specified size of the shared memory; and format the shared memory according to the specified formatting rule;
如果判断出所述共享内存已经分配,则获取通过校验的所述共享内存。If it is determined that the shared memory has been allocated, the shared memory that has passed the verification is acquired.
在一些实施例中,可以通过具体操作系统的系统调用判断所需的共享内存是否已经分配,若没有分配,则调用本地系统调用或自定义的共享内存分配接口根据需要的共享内存大小分配新的共享内存,并将共享内存按指定的格式化规则格式化为需要的格式,例如可以将共享内存划分为元数据区和存储数据区,元数据区记录数据是如何被存储在存储数据区的,存储数据区存储需要存储的实际数据;再例如,将整个共享内存都作为存储区,顺序写入实际数据,等等,此处列举的格式化方式不作为对本发明技术方案的格式化规则的具体限制,技术人员可根据自身项目需要自行定义具体的格式化规则。若所需的共享内存已经分配,则打开该共享内存,获得该共享内存的描述符、句柄或指针等,读取该共享内存中的数据,进行必要的校验,例如共享内存的版本是否符合预期的版本、共享内存中的数据是否有损坏或丢失等,校验成功后,返回该共享内存的描述符、句柄或指针等用于本地读写接口操作该共享内存。在具体实施时,如图3所示,可以预先将本发明实施例中的上述步骤部署在各本地应用中;也可以如图2所示,预先将本发明实施例中的上述步骤部署在网络接口模块中;也可以预先将本发明实施例中的上述步骤既部署在各本地应用也部署在网络接口模块中。最先启动的任一本地应用或网络接口模块会检测到共享内存没有分配,从而分配该共享内存,随后启动的本地应用或网络接口模块检测到所需的共享内存已经分配,则直接打开该共享内存。例如在通过linux系统中的XSI共享内存方式实现本实施例的共享内存时,可定义系统全局唯一的标识来标识本实施例中的共享内存,在各本地应用以及网络接口模块中通过该全局唯一的标识以及与XSI共享内存相关的系统调用操作共享内存。In some embodiments, it can be determined whether the required shared memory has been allocated through a system call of a specific operating system, and if not allocated, a local system call or a custom shared memory allocation interface is called to allocate a new shared memory according to the required shared memory size. Shared memory, and format the shared memory into the required format according to the specified formatting rules. For example, the shared memory can be divided into a metadata area and a storage data area. The metadata area records how the data is stored in the storage data area. The storage data area stores the actual data that needs to be stored; for another example, the entire shared memory is used as a storage area, and the actual data is written in sequence, etc. The formatting methods listed here are not specific to the formatting rules of the technical solution of the present invention. Restrictions, technicians can define specific formatting rules according to their own project needs. If the required shared memory has been allocated, open the shared memory, obtain the descriptor, handle or pointer of the shared memory, read the data in the shared memory, and perform necessary checks, such as whether the version of the shared memory conforms to The expected version, whether the data in the shared memory is damaged or lost, etc. After the verification is successful, the descriptor, handle or pointer of the shared memory is returned for the local read-write interface to operate the shared memory. During specific implementation, as shown in FIG. 3 , the above steps in the embodiment of the present invention may be deployed in each local application in advance; as shown in FIG. 2 , the above steps in the embodiment of the present invention may be pre-deployed in the network In the interface module; the above steps in the embodiment of the present invention may also be pre-deployed in each local application and in the network interface module. Any local application or network interface module that is started first will detect that the shared memory is not allocated and allocate the shared memory. The local application or network interface module that is started subsequently detects that the required shared memory has been allocated, and directly opens the shared memory. Memory. For example, when the shared memory of this embodiment is implemented through the XSI shared memory method in the Linux system, a globally unique identifier of the system can be defined to identify the shared memory in this embodiment, and the globally unique identifier can be used in each local application and the network interface module through the globally unique identifier. The identifier of the shared memory as well as system calls related to XSI shared memory operations.
本发明实施例具有如下技术效果:通过判断共享内存是否存在决定创建新的共享内存或打开已经存在的共享内存,可以各本地应用和网络接口模块同时打开同一个共享内存,达到各本地应用和远程应用通过同一共享内存操作指定格式的数据的效果。The embodiments of the present invention have the following technical effects: by judging whether a shared memory exists and deciding to create a new shared memory or open an existing shared memory, each local application and the network interface module can open the same shared memory at the same time, so that each local application and remote Applies the effect of data in the specified format through the same shared memory operation.
进一步地,所述共享内存包括头部内存和至少一个存储区;Further, the shared memory includes a header memory and at least one storage area;
所述根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存,包括:Allocating the shared memory in the local system according to the pre-specified size of the shared memory; and formatting the shared memory according to a specified formatting rule, including:
在本地系统中按所述共享内存的大小分配所述共享内存;Allocate the shared memory in the local system according to the size of the shared memory;
根据预先指定的所有存储区所占用空间的起始地址和终止地址、每个存储区各自的扇区数和扇区大小决定因子,计算出可划分出的存储区数量;Calculate the number of storage areas that can be divided according to the pre-specified start and end addresses of the space occupied by all storage areas, the number of sectors in each storage area and the sector size determination factor;
根据所述共享内存的头部内存需要保存的头部信息和所述存储区数量,计算出需要保留的头部内存的大小;将所述共享内存划分为所述头部内存和所述至少一个存储区;其中,所述头部信息包括:共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和指定数组长度的木桶数组;Calculate the size of the header memory to be reserved according to the header information to be saved in the header memory of the shared memory and the number of storage areas; divide the shared memory into the header memory and the at least one Storage area; wherein, the header information includes: the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, the starting address of the sector linked list corresponding to each storage area and the specified array length. cask array;
将每个存储区按该存储区的特定扇区字节数格式化为至少一个扇区;其中,各存储区对应的特定扇区字节数根据扇区大小决定因子得到;Each storage area is formatted into at least one sector according to the specific sector byte number of the storage area; wherein, the specific sector byte number corresponding to each storage area is obtained according to the sector size determination factor;
针对每个存储区,将该存储区中的所有扇区的地址以链表方式保存在与该存储区对应的链表中,将该链表作为该存储区对应的扇区链表;For each storage area, the addresses of all sectors in the storage area are stored in the linked list corresponding to the storage area in a linked list, and the linked list is used as the sector linked list corresponding to the storage area;
将所述共享内存的版本、所述头部内存的大小、所述共享内存的大小、所述读写锁、各存储区各自对应的扇区链表的起始地址和设置为空的所述木桶数组保存在所述头部内存中;The version of the shared memory, the size of the head memory, the size of the shared memory, the read-write lock, the starting address of the sector linked list corresponding to each storage area and the wood set to be empty. The bucket array is stored in the header memory;
所述获取通过校验的所述共享内存,包括:The obtaining of the shared memory that has passed the verification includes:
打开本地系统中已经分配的所述共享内存;open the shared memory that has been allocated in the local system;
从所述头部内存中读取所述共享内存的版本;read a version of the shared memory from the header memory;
将所述共享内存的版本与指定内存版本比较,如果所述共享内存的版本兼容所述指定内存版本,则返回共享内存可用的信息并获取所述共享内存;Compare the version of the shared memory with the specified memory version, and if the version of the shared memory is compatible with the specified memory version, return the information that the shared memory is available and obtain the shared memory;
其中,所述木桶数组的每个数组元素用于保存由已经写入指定格式的数据的扇区构成的链表的起始地址。Wherein, each array element of the bucket array is used to store the starting address of the linked list formed by the sectors in which the data of the specified format has been written.
在一些实施例中,根据具体的系统,调用该系统的本地系统调用或者自定义的本地共享内存分配接口,根据所需的共享内存的大小分配共享内存;在确定头部内存大小时,可以通过预先指定所有存储区所占用空间的起始地址和预先指定的所有存储区所占用空间的终止地址来为头部内存保留足够的空间;将预先指定的所有存储区所占用空间的终止地址减去预先指定所有存储区所占用空间的起始地址得到可用于存储区的可用存储区空间的大小;通过扇区大小决定因子和预先指定的最小扇区字节数来确定其他存储区的扇区字节数,具体的,针对第N个存储区,将扇区大小决定因子的(N-1)次幂的值再乘以最小扇区字节数作为第N个存储区的特定扇区字节数,将各存储区的特定扇区字节数乘以预先为各存储区定义的扇区数,可以得到预计需要的预计存储空间,通过调整存储区的数量使预计存储空间不超过可用存储区空间,从而得到存储区的数量;其中,N为大于等于1的整数,通过查找使预计存储空间不超过可用存储区空间的最大的N值即得到存储区的数量。例如,预先定义最小扇区为32字节,扇区大小决定因子为2,则第一个存储区中的各扇区大小为32字节,第二个存储区中的各扇区的大小为32*2=64字节,第三个存储区中的各扇区的大小为64*2=128字节,依此类推,将各存储区的特定扇区字节数乘以预先为各存储区定义的扇区数,可以得到预计需要的预计存储空间,通过调整存储区的数量使预计存储空间不超过可用存储区空间,从而得到存储区的数量;头部信息包括:共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和指定数组长度的木桶数组;将上述各部分占用的空间加总,即得到头部内存的大小。将各存储区按顺序部署在头部内存的后面,可以与头部内存相邻或保留指定的空闲区域。针对每一个存储区,将该存储区按其特定扇区字节数划分为一个或多个扇区,并获得各扇区的地址,将各扇区以链表的方式组织成为与该存储区对应的扇区链表。将共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和设置为空的木桶数组保存在头部内存中;完成对共享内存的格式化,此时由于木桶数组为空,所以共享内存中还没有写入任何存储数据。In some embodiments, according to a specific system, a local system call of the system or a self-defined local shared memory allocation interface is called, and the shared memory is allocated according to the required size of the shared memory; when determining the size of the header memory, the Pre-specify the start address of the space occupied by all storage areas and the end address of the space occupied by all the pre-specified storage areas to reserve enough space for the head memory; subtract the end address of the space occupied by all the pre-specified storage areas from the Pre-specify the starting address of the space occupied by all storage areas to obtain the size of the available storage area space that can be used for the storage area; determine the sector words of other storage areas through the sector size determination factor and the pre-specified minimum number of sector bytes The number of sections, specifically, for the Nth storage area, multiply the value of the sector size determination factor to the power of (N-1) by the minimum number of sector bytes as the specific sector bytes of the Nth storage area By multiplying the number of bytes in a specific sector of each storage area by the number of sectors defined for each storage area in advance, the estimated storage space required can be obtained. By adjusting the number of storage areas, the estimated storage space does not exceed the available storage area. space to obtain the number of storage areas; wherein, N is an integer greater than or equal to 1, and the number of storage areas is obtained by finding the largest N value that makes the expected storage space not exceed the available storage area space. For example, the pre-defined minimum sector is 32 bytes, and the sector size determination factor is 2, then the size of each sector in the first storage area is 32 bytes, and the size of each sector in the second storage area is 32*2=64 bytes, the size of each sector in the third storage area is 64*2=128 bytes, and so on, multiply the specific sector bytes of each storage area by The number of sectors defined in the area can be used to obtain the estimated storage space required. By adjusting the number of storage areas so that the expected storage space does not exceed the available storage area space, the number of storage areas can be obtained; the header information includes: the version of the shared memory, The size of the header memory, the size of the shared memory, the read-write lock, the starting address of the sector linked list corresponding to each storage area, and the bucket array with the specified array length; add up the space occupied by the above parts to get the header the size of the external memory. Each storage area is sequentially deployed behind the header memory, which can be adjacent to the header memory or reserve a designated free area. For each storage area, divide the storage area into one or more sectors according to the number of bytes of its specific sector, obtain the address of each sector, and organize each sector in a linked list to correspond to the storage area sector list. Save the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, the starting address of the sector list corresponding to each storage area, and the empty bucket array in the header memory; complete For the format of shared memory, since the bucket array is empty, no storage data has been written to the shared memory.
当打开已经存在的共享内存时,例如在网络接口模块中部署了内存检测单元、内存创建单元和内存获取单元,首先启动了网络接口模块,此时网络接口模块发现没有可用的共享内存,会通过内存创建单元创建并格式化新的共享内存;然后,本地应用启动,在本地应用中,也部署了内存检测单元、内存创建单元和内存获取单元,本地应用发现共享内存已经存在,此时本地应用需要打开共享内存,并校验共享内存的版本是否与期望的指定内存版本兼容,若兼容,则允许本地应用继续使用该共享内存,可以通过获得该共享内存的描述符、句柄或指针等参数供共享内存的本地读写接口操作该共享内存;相同,若不相同,当存在不兼容的情况时,需要终止本地应用对该共享内存的访问在另一些实施例中,也可能出现先启动本地应用再启动网络接口模块,可依据上述实施例理解不同启动顺序下的共享内存分配和获取过程。在进行版本兼容性判断时,可以通过比较共享内存的版本与指定内存版本的大小关系确定,例如共享内存的版本与指定内存版本相等时为兼容、或者共享内存的版本大于和/或等于指定内存版本时表示兼容、或者共享内存的版本小于和/或等于指定内存版本时表示兼容、或者指定内存版本表示一个版本范围,只要共享内存的版本在这个版本范围内就表示兼容。When the existing shared memory is opened, for example, the memory detection unit, the memory creation unit and the memory acquisition unit are deployed in the network interface module, and the network interface module is started first. At this time, the network interface module finds that there is no available shared memory, and will pass The memory creation unit creates and formats new shared memory; then, the local application starts, and the memory detection unit, memory creation unit and memory acquisition unit are also deployed in the local application. The local application finds that the shared memory already exists. At this time, the local application It is necessary to open the shared memory and check whether the version of the shared memory is compatible with the expected specified memory version. If it is compatible, the local application is allowed to continue to use the shared memory. You can obtain the descriptor, handle or pointer of the shared memory and other parameters for The local read-write interface of the shared memory operates the shared memory; the same, if not the same, when there is an incompatibility, the local application needs to terminate the access to the shared memory. In other embodiments, it may also occur that the local application is started first. After restarting the network interface module, the shared memory allocation and acquisition processes in different startup sequences can be understood according to the above embodiments. When judging version compatibility, it can be determined by comparing the size relationship between the shared memory version and the specified memory version. For example, when the shared memory version is equal to the specified memory version, it is compatible, or the shared memory version is greater than and/or equal to the specified memory version. The version indicates compatibility, or the shared memory version is less than and/or equal to the specified memory version, indicating compatibility, or the specified memory version indicates a version range, as long as the shared memory version is within this version range, it indicates compatibility.
本发明实施例具有如下技术效果:根据共享内存的大小还其他预先给定的参数自行格式化共享内存,并且将共享内存按不同的扇区大小格式化为多个存储区,可以根据具体存储的数据大小选择合适的存储区,避免内存浪费,同时仍能保持较高的内存读写效率。The embodiment of the present invention has the following technical effects: the shared memory is formatted by itself according to the size of the shared memory and other predetermined parameters, and the shared memory is formatted into multiple storage areas according to different sector sizes, which can be stored according to the specific storage area. Select the appropriate storage area for the data size to avoid memory waste, while still maintaining high memory read and write efficiency.
进一步地,所述指定网络协议包括Memcache协议和Redis协议;Further, the specified network protocol includes Memcache protocol and Redis protocol;
所述指定格式包括键字符串和取值;The specified format includes a key string and a value;
所述调用预先实现的本地读写接口按所述指定格式在共享内存中读取或设置所述存储数据,包括:The calling of the pre-implemented local read/write interface reads or sets the stored data in the shared memory according to the specified format, including:
使用哈希算法将所述存储数据中的所述键字符串转换成哈希值;将所述哈希值除以所述木桶数组的长度,获取余数;Convert the key string in the stored data into a hash value using a hash algorithm; divide the hash value by the length of the bucket array to obtain the remainder;
如果调用本地读写接口的读取操作,则针对所述共享内存加读锁,找到所述木桶数组中第所述余数位置处的数组元素保存的链表的起始地址,将找到的链表作为待遍历链表;遍历所述待遍历链表的元素,如果发现某个元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回该元素对应的扇区中记录的取值;如果没有发现任何元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回键字符串不存在的错误信息;If the read operation of the local read-write interface is invoked, a read lock is added to the shared memory, and the starting address of the linked list stored by the array element at the remainder position in the bucket array is found, and the found linked list is used as The linked list to be traversed; the elements of the linked list to be traversed are traversed, if it is found that the key string recorded in the sector corresponding to a certain element is the same as the key string corresponding to the stored data, then the record in the sector corresponding to the element is returned If it is not found that the key string recorded in the sector corresponding to any element is the same as the key string corresponding to the stored data, the error message that the key string does not exist is returned;
如果调用本地读写接口的写入操作,则针对所述共享内存加写锁,并计算所述存储数据的键字符串和取值的总占用空间长度;将所述总占用空间长度与每个存储区的特定扇区字节数比较,确定保存所述存储数据所需的最小特定扇区字节数;在所述最小特定扇区字节数对应的存储区对应的扇区链表中查找一个空闲扇区,如果没有找到任何空闲扇区,则返回无可用内存的错误信息,如果找到空闲扇区则将所述存储数据的键字符串和取值复制到该空闲扇区,将该空闲扇区添加到所述木桶数组中第所述余数位置处的数组元素保存的链表中,并将该空闲扇区标识为已用。If the write operation of the local read-write interface is invoked, a write lock is added to the shared memory, and the total occupied space length of the key string and value of the stored data is calculated; the total occupied space length and each Compare the number of bytes in a specific sector of the storage area, and determine the minimum number of bytes in a specific sector required to save the stored data; search for a sector linked list corresponding to the storage area corresponding to the minimum number of bytes in a specific sector Free sector, if no free sector is found, an error message of no available memory is returned. If a free sector is found, the key string and value of the stored data are copied to the free sector, and the free sector The area is added to the linked list saved by the array element at the remainder position in the bucket array, and the free sector is marked as used.
在一些实施例中,指定网络协议包括Memcache协议和Redis协议,对于已经使用了Memcache和Redis的项目,可以使用本方法实现的系统无缝替换现存的项目,不影响现存项目的其他部分,达到快速更新各现存项目,提高开发效率的目的。通过哈希算法将存储数据中的键字符串转换为哈希值,例如一个32位的整数值,再将该哈希值对木桶数组的数组长度求余,得到余数;木桶数组的每个数组元素用于保存由已经写入指定格式的数据的扇区构成的链表的起始地址;在木桶数组的该余数位置处的元素中保存的是该存储数据所在的或者即将加入的待遍历链表的起始地址;当在从共享内存中读取指定键字符串的取值时,通过设置头部内存的读写锁,针对共享内存加读锁,读锁不会导致禁止其他读取操作,但会禁止其他写入操作,并且根据得到的余数可以得到保存该键字符串和取值的扇区所在的待遍历链表的起始地址,遍历这个待遍历链表中的每个元素对应的扇区,当发现该键字符串时,从该扇区中取出相应的取值;若遍历结束后仍没有发现该键字符串,则说明当前共享内存中没有该键字符串及其取值,返回键字符串不存在的错误信息。当调用本地读写接口的写入操作时,通过设置头部内存的读写锁,针对共享内存加写锁,禁止其他的读写操作,并且计算存储数据的键字符换和取值的总占用空间,将所述总占用空间长度与每个存储区的特定扇区字节数比较,在比较时需要将已用标记等控制字段或存储格式辅助字段占用的字节数考虑在内,确定保存所述存储数据所需的最小特定扇区字节数;例如键值字符串和取值的总占用空间为29字节,共享内存格式化后,共有3个存储区,各自的扇区字节数分别为16字节、32字节、64字节,每个扇区都需要1个字节作为已用标识,此时,可以发现第2存储区的扇区字节数是大于29+1=30字节的最小的扇区字节数,所以确定将该29字节的存储数据保存在第2存储区的某个扇区中;在第2存储区对应的扇区链表中查找空闲扇区,若找到,则将该29字节的存储数据写入找到的空闲扇区,并且将该空闲扇区追加到木桶数组中再前述余数位置处的链表中,并且将该空闲扇区标识为已用。In some embodiments, the specified network protocol includes the Memcache protocol and the Redis protocol. For projects that have already used Memcache and Redis, the system implemented by this method can seamlessly replace the existing project without affecting other parts of the existing project. The purpose of updating existing projects and improving development efficiency. Convert the key string in the stored data into a hash value, such as a 32-bit integer value, through a hash algorithm, and then take the remainder of the hash value with the array length of the bucket array to get the remainder; each value of the bucket array The array elements are used to save the starting address of the linked list composed of sectors that have written data in the specified format; the element at the remainder position of the bucket array stores the storage data where the stored data is located or is about to be added. Traverse the starting address of the linked list; when reading the value of the specified key string from the shared memory, by setting the read-write lock of the head memory, the read lock is added to the shared memory, and the read lock will not prevent other reads. operation, but other write operations will be prohibited, and according to the obtained remainder, the starting address of the linked list to be traversed where the key string and the sector where the value is stored can be obtained, and the corresponding element of each element in the linked list to be traversed can be traversed Sector, when the key string is found, the corresponding value is taken from the sector; if the key string is not found after the traversal is completed, it means that the key string and its value do not exist in the current shared memory. Returns an error message if the key string does not exist. When calling the write operation of the local read-write interface, set the read-write lock of the head memory, add a write lock to the shared memory, prohibit other read-write operations, and calculate the total occupancy of the key character exchange and value of the stored data space, compare the length of the total occupied space with the number of bytes in a specific sector of each storage area, and when comparing, it is necessary to take into account the number of bytes occupied by control fields such as used tags or auxiliary fields of storage formats, and determine to save The minimum number of specific sector bytes required to store the data; for example, the total occupied space of the key-value string and the value is 29 bytes. After the shared memory is formatted, there are a total of 3 storage areas, and the respective sector bytes The numbers are 16 bytes, 32 bytes, and 64 bytes, and each sector requires 1 byte as the used identifier. At this time, it can be found that the number of bytes of the sector in the second storage area is greater than 29+1 = The minimum number of sector bytes of 30 bytes, so it is determined to save the 29-byte storage data in a certain sector of the second storage area; search for free sectors in the sector list corresponding to the second storage area area, if found, write the 29-byte storage data into the found free sector, append the free sector to the linked list at the position of the remainder in the bucket array, and identify the free sector for used.
本发明实施例具有如下技术效果:通过哈希算法将存储数据分散到木桶数组的不同索引位置的链表上,以及通过设置合适的木通数组的指定数组长度值,可以高效的读写存储数据提高共享内存的读写效率。例如使用较大的木桶数组的指定数组长度可以显著减少每个待遍历链表的长度,减少遍历时间,提高读写效率。The embodiment of the present invention has the following technical effects: the stored data is dispersed on the linked list of different index positions of the wooden bucket array by the hash algorithm, and the specified array length value of the suitable wooden pass array can be set, so that the stored data can be read and written efficiently. Improve the read and write efficiency of shared memory. For example, using the specified array length of a larger bucket array can significantly reduce the length of each linked list to be traversed, reduce the traversal time, and improve read and write efficiency.
进一步地,还包括:Further, it also includes:
根据指定持久化规则,调用本地读写接口将所述共享内存中的指定格式的数据持久化到持久存储装置中;并且在重新启动时,从所述持久存储装置中加载所述指定格式的数据到所述共享内存。According to the specified persistence rule, the local read-write interface is called to persist the data in the specified format in the shared memory to the persistent storage device; and when restarting, the data in the specified format is loaded from the persistent storage device to the shared memory.
在一些实施例中,如图5所示,当满足指定的持久化规则时例如包括但不限于等待共享内存中的存储数据量达到指定的阈值或者距离上一次持久化操作达到指定的超时时间时,,调用本地读写接口的读取操作,从共享内存中读取其保存的数据,写入持久存储装置例如磁盘中,达到掉电不丢失的目的。在系统重启后,获取共享内存的句柄,并读取本地持久化存储装置中的持久化数据文件,若存在持久化数据,则将持久存储装置中保存的持久化数据重新加载到共享内存中,继续提供远程和/或本地的请求。In some embodiments, as shown in FIG. 5 , when a specified persistence rule is satisfied, for example, including but not limited to waiting for the amount of stored data in the shared memory to reach a specified threshold or a specified timeout period from the last persistence operation , call the read operation of the local read/write interface, read the data stored in the shared memory, and write it into a persistent storage device such as a disk, so as to achieve the purpose of not being lost when power is turned off. After the system restarts, the handle of the shared memory is obtained, and the persistent data file in the local persistent storage device is read. If there is persistent data, the persistent data saved in the persistent storage device is reloaded into the shared memory. Continue to serve remote and/or local requests.
另一方面,如图6所示,本发明实施例提供一种数据存储装置,包括:On the other hand, as shown in FIG. 6 , an embodiment of the present invention provides a data storage device, including:
网络读写单元600,用于响应于收到的按指定网络协议读写指定格式的存储数据的远程读写请求,触发本地读写模块完成调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;The network read-
本地读写单元601,用于响应于收到的读写所述指定格式的存储数据的本地读写请求,触发所述本地读写模块完成调用预先实现的本地读写接口按所述指定格式在共享内存中读取或写入所述存储数据;The local read-
所述共享内存是在本地系统中分配的用于一个或多个进程以共享的方式读写数据的内存。The shared memory is memory allocated in the local system for one or more processes to read and write data in a shared manner.
进一步地,还包括:Further, it also includes:
内存检测单元,用于在收到所述远程读写请求或所述本地读写请求后,在共享内存中读取或写入所述存储数据之前,判断所述共享内存是否已经分配;a memory detection unit, configured to determine whether the shared memory has been allocated before reading or writing the stored data in the shared memory after receiving the remote read/write request or the local read/write request;
内存创建单元,用于如果判断出所述共享内存没有分配,则根据预先指定的所述共享内存的大小在本地系统中分配所述共享内存;并且按指定格式化规则格式化所述共享内存;A memory creation unit, configured to allocate the shared memory in the local system according to the pre-specified size of the shared memory if it is judged that the shared memory is not allocated; and format the shared memory according to a specified formatting rule;
内存获取单元,用于如果判断出所述共享内存已经分配,则获取通过校验的所述共享内存。A memory acquisition unit, configured to acquire the shared memory that has passed the verification if it is determined that the shared memory has been allocated.
进一步地,所述共享内存包括头部内存和至少一个存储区;Further, the shared memory includes a header memory and at least one storage area;
所述内存创建单元,包括:The memory creation unit includes:
共享内存分配模块,用于在本地系统中按所述共享内存的大小分配所述共享内存;a shared memory allocation module, configured to allocate the shared memory in the local system according to the size of the shared memory;
存储区数量规划模块,用于根据预先指定的所有存储区所占用空间的起始地址和终止地址、每个存储区各自的扇区数和扇区大小决定因子,计算可划分出的存储区数量;The storage area quantity planning module is used to calculate the number of storage areas that can be divided according to the pre-specified start and end addresses of the space occupied by all storage areas, the number of sectors and sector size determination factors for each storage area. ;
第一格式化模块,用于根据所述共享内存的头部内存需要保存的头部信息和所述存储区数量,计算出需要保留的头部内存的大小;将所述共享内存划分为所述头部内存和所述至少一个存储区;其中,所述头部信息包括:共享内存的版本、头部内存的大小、共享内存的大小、读写锁、各存储区各自对应的扇区链表的起始地址和指定数组长度的木桶数组;The first formatting module is used to calculate the size of the header memory that needs to be reserved according to the header information that needs to be saved in the header memory of the shared memory and the number of storage areas; the shared memory is divided into the The header memory and the at least one storage area; wherein, the header information includes: the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, and the corresponding sector list of each storage area. The starting address and the array of barrels with the specified array length;
第二格式化模块,用于将每个存储区按该存储区的特定扇区字节数格式化为至少一个扇区;其中,各存储区对应的特定扇区字节数根据扇区大小决定因子得到;The second formatting module is used to format each storage area into at least one sector according to the number of bytes of the specific sector of the storage area; wherein, the number of bytes of the specific sector corresponding to each storage area is determined according to the size of the sector factor is obtained;
第三格式化模块,用于针对每个存储区,将该存储区中的所有扇区的地址以链表方式保存在与该存储区对应的链表中,将该链表作为该存储区对应的扇区链表;The third formatting module is used for, for each storage area, the addresses of all sectors in the storage area are stored in the linked list corresponding to the storage area in a linked list, and the linked list is used as the sector corresponding to the storage area linked list;
第四格式化模块,用于将所述共享内存的版本、所述头部内存的大小、所述共享内存的大小、所述读写锁、各存储区各自对应的扇区链表的起始地址和设置为空的所述木桶数组保存在所述头部内存中;The fourth formatting module is used to format the version of the shared memory, the size of the header memory, the size of the shared memory, the read-write lock, and the starting address of the sector linked list corresponding to each storage area. and the bucket array set to empty is stored in the header memory;
所述内存获取单元,具体配置为:打开本地系统中已经分配的所述共享内存;从所述头部内存中读取所述共享内存的版本;将所述共享内存的版本与指定内存版本比较,如果所述共享内存的版本兼容所述指定内存版本,则返回共享内存可用的信息并获取所述共享内存;The memory acquisition unit is specifically configured to: open the shared memory that has been allocated in the local system; read the version of the shared memory from the head memory; compare the version of the shared memory with the specified memory version , if the version of the shared memory is compatible with the specified memory version, return the information that the shared memory is available and obtain the shared memory;
其中,所述木桶数组的每个数组元素用于保存由已经写入指定格式的数据的扇区构成的链表的起始地址。Wherein, each array element of the bucket array is used to store the starting address of the linked list formed by the sectors in which the data of the specified format has been written.
进一步地,所述指定网络协议包括Memcache协议和Redis协议;Further, the specified network protocol includes Memcache protocol and Redis protocol;
所述指定格式包括键字符串和取值;The specified format includes a key string and a value;
所述本地读写模块,包括:The local read-write module includes:
读写位置获取模块,用于使用哈希算法将所述存储数据中的所述键字符串转换成哈希值;将所述哈希值除以所述木桶数组的长度,获取余数;a read-write position acquisition module, used to convert the key string in the stored data into a hash value using a hash algorithm; divide the hash value by the length of the bucket array to obtain the remainder;
读取模块,用于如果调用本地读写接口的读取操作,则针对所述共享内存加读锁,找到所述木桶数组中第所述余数位置处的数组元素保存的链表的起始地址,将找到的链表作为待遍历链表;遍历所述待遍历链表的元素,如果发现某个元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回该元素对应的扇区中记录的取值;如果没有发现任何元素对应的扇区中记录的键字符串与所述存储数据对应的键字符串相同,则返回键字符串不存在的错误信息;The reading module is used to add a read lock to the shared memory if the read operation of the local read-write interface is called, and find the starting address of the linked list stored by the array element at the remainder position in the bucket array , take the found linked list as the linked list to be traversed; traverse the elements of the linked list to be traversed, if it is found that the key string recorded in the sector corresponding to a certain element is the same as the key string corresponding to the stored data, then return the element The value recorded in the corresponding sector; if it is not found that the key character string recorded in the sector corresponding to any element is the same as the key character string corresponding to the stored data, the error message that the key character string does not exist is returned;
写入模块,用于如果调用本地读写接口的写入操作,则针对所述共享内存加写锁,并计算所述存储数据的键字符串和取值的总占用空间长度;将所述总占用空间长度与每个存储区的特定扇区字节数比较,确定保存所述存储数据所需的最小特定扇区字节数;在所述最小特定扇区字节数对应的存储区对应的扇区链表中查找一个空闲扇区,如果没有找到任何空闲扇区,则返回无可用内存的错误信息,如果找到空闲扇区则将所述存储数据的键字符串和取值复制到该空闲扇区,将该空闲扇区添加到所述木桶数组中第所述余数位置处的数组元素保存的链表中,将该空闲扇区从所述最小特定扇区字节数对应的存储区对应的扇区链表中移除。The writing module is used to add a write lock to the shared memory if the write operation of the local read-write interface is called, and calculate the total occupied space length of the key string and the value of the stored data; The length of the occupied space is compared with the number of bytes of a specific sector of each storage area to determine the minimum number of bytes of a specific sector required to save the storage data; Find a free sector in the sector linked list, if no free sector is found, return the error message of no available memory, if a free sector is found, copy the key string and value of the stored data to the free sector area, add the free sector to the linked list saved by the array element at the remainder position in the barrel array, and remove the free sector from the storage area corresponding to the minimum specific sector bytes Removed from the sector list.
进一步地,还包括:Further, it also includes:
持久化单元,用于根据指定持久化规则,调用本地读写接口将所述共享内存中的指定格式的数据持久化到持久存储装置中;并且在重新启动时,从所述持久存储装置中加载所述指定格式的数据到所述共享内存。A persistence unit, configured to call the local read-write interface to persist the data in the specified format in the shared memory to the persistent storage device according to the specified persistence rule; and when restarting, load from the persistent storage device The data in the specified format is transferred to the shared memory.
本发明实施例提供的数据存储装置是与前述的数据存储方法一一对应的产品类实施例,本领域技术人员可根据前述的数据存储方法的实施例理解数据存储装置的实施例,在此不再赘述。The data storage device provided by the embodiment of the present invention is a product-type embodiment corresponding to the foregoing data storage method one-to-one. Those skilled in the art can understand the embodiment of the data storage device according to the foregoing embodiment of the data storage method. Repeat.
本发明实施例具有如下技术效果:通过使用共享内存并提供读写共享内存的本地读写接口允许本地应用程序绕过网络协议栈,直接与基于共享内存的数据库对应的内存区域进行交互,从而获得极高的性能,同时可兼容指定网络协议的远程读写请求。通过共享内存的机制,基于同一个共享内存实现的数据存储可以同时被多个本地应用程序和组件共享,也支持通过指定网络协议被多个外部用户远程访问。进一步地,通过按指定持久化规则将数据持久化,即使在机器重启的情况下也可以保证数据不会丢失。The embodiments of the present invention have the following technical effects: by using the shared memory and providing a local read-write interface for reading and writing the shared memory, the local application program can bypass the network protocol stack and directly interact with the memory area corresponding to the shared memory-based database, thereby obtaining Extremely high performance, and compatible with remote read and write requests of specified network protocols. Through the shared memory mechanism, data storage based on the same shared memory can be shared by multiple local applications and components at the same time, and also supports remote access by multiple external users through a specified network protocol. Further, by persisting the data according to the specified persistence rules, it is guaranteed that the data will not be lost even when the machine is restarted.
下面结合具体的应用实例对本发明实施例上述技术方案进行详细说明,实施过程中没有介绍到的技术细节,可以参考前文的相关描述。The foregoing technical solutions of the embodiments of the present invention will be described in detail below with reference to specific application examples. For technical details not introduced in the implementation process, reference may be made to the foregoing related descriptions.
本发明实施例包含4个模块,分别是由服务器自身内存提供的共享内存,网络接口模块,本地库接口模块,数据持久化模块。The embodiment of the present invention includes four modules, which are a shared memory provided by the server's own memory, a network interface module, a local library interface module, and a data persistence module.
各个模块之间关系可以参考图4,图中的箭头可以表明各个模块之间的数据流向,由于模块与模块之间是松耦合关系,除了共用一段共享的内存之外,不存在明确的模块间的数据流动,每个模块都可以独立的工作。The relationship between the modules can refer to Figure 4. The arrows in the figure can indicate the data flow between the modules. Since the modules are loosely coupled, there is no clear relationship between modules except for sharing a shared memory. data flow, each module can work independently.
其中,共享内存由服务器自身的共享内存功能提供;网络接口模块,通过监听的TCP端口对服务器外部提供基于网络的服务,服务协议包括Memcache协议和Redis协议;持久化模块用于根据指定规则将共享内存中的内容持久化到磁盘中,并在重新启动时加载磁盘中的数据到共享内存。Among them, the shared memory is provided by the shared memory function of the server itself; the network interface module provides network-based services to the outside of the server through the monitored TCP port, and the service protocols include Memcache protocol and Redis protocol; persistence module is used to share The contents of memory are persisted to disk, and data from disk is loaded into shared memory on reboot.
针对本地接口库模块,其工作方式和流程图可简单描述为图3。For the local interface library module, its working mode and flow chart can be simply described as Figure 3.
针对网络接口模块,其工作方式和流程图可简单描述为图2:For the network interface module, its working mode and flow chart can be simply described as Figure 2:
针对上述两个模块的【打开共享内存句柄或申请共享内存】阶段,主要流程为:For the above two modules [open shared memory handle or apply for shared memory] stage, the main process is as follows:
1.判断共享内存块是否存在,如果不存在,转2,否则转6;1. Determine whether the shared memory block exists, if not, go to 2, otherwise go to 6;
2.调用系统调用,创建一块共享内存;2. Call the system call to create a shared memory;
3.根据共享内存大小,计算出需要保留的头部内存大小META_SIZE;3. According to the shared memory size, calculate the META_SIZE of the header memory size that needs to be reserved;
3.1根据MIN_SLAB_SIZE、MAX_SLAB_SIZE和SLAB_FACTOR,计算出所需要的SLAB的数量slabcount;3.1 According to MIN_SLAB_SIZE, MAX_SLAB_SIZE and SLAB_FACTOR, calculate the required number of SLABs slabcount;
3.2设一个链表头需要的存储空间为HEADER_SIZE,共享内存版本号存储空间为VERSION_SIZE,读写锁存储空间为LOCK_SIZE,则META_SIZE的计算公式为:3.2 Suppose the storage space required for a linked list header is HEADER_SIZE, the shared memory version number storage space is VERSION_SIZE, and the read-write lock storage space is LOCK_SIZE, then the calculation formula of META_SIZE is:
META_SIZE=VERSION_SIZE+LOCK_SIZE+slabcount*HEADER_SIZE+len(buckets)*HEADER_SIZE;META_SIZE=VERSION_SIZE+LOCK_SIZE+slabcount*HEADER_SIZE+len(buckets)*HEADER_SIZE;
4.将共享内存从META_SIZE往后的部分,根据配置,从MIN_SLAB_SIZE(即预先指定的所有存储区所占用空间的起始地址)开始,到MAX_SLAB_SIZE(即预先指定的所有存储区所占用空间的终止地址)结束,预先指定的所有存储区所占用空间即可用存储区空间的大小,以SLAB_FACTOR(即扇区大小决定因子,优选的值为2)的步调,将内存分割成若干个小块SLAB(即扇区),并将这些小块的内存地址,以SLAB_SIZE(即每个存储区各自的特定扇区字节数)进行分组,用链表的形式进行保存(即针对每个存储区,将该存储区中的所有扇区的地址以链表方式保存在与该存储区对应的链表中,将该链表作为该存储区对应的扇区链表);4. Set the shared memory from META_SIZE onwards, according to the configuration, from MIN_SLAB_SIZE (that is, the starting address of the space occupied by all pre-specified storage areas) to MAX_SLAB_SIZE (that is, the termination of the space occupied by all pre-specified storage areas) address), the space occupied by all the pre-specified storage areas is the size of the available storage area space, and the memory is divided into several small blocks SLAB_FACTOR (that is, the sector size determining factor, the preferred value is 2) at the pace of the step. That is, sectors), and group the memory addresses of these small blocks in SLAB_SIZE (that is, the number of bytes in each specific sector of each storage area), and save them in the form of a linked list (that is, for each storage area, this The addresses of all sectors in the storage area are stored in the linked list corresponding to the storage area in a linked list, and the linked list is used as the sector linked list corresponding to the storage area);
5.将当前库的版本(即共享内存版本),META_SIZE(即头部内存的大小),共享内存总大小,步骤4中所有SLAB链表的地址(即各存储区对应的各自的扇区链表的起始地址),一个空的buckets数组(即木桶数组),存放到内存从0到META_SIZE之间的区域(即头部内存中),转步骤10;5. Set the version of the current library (that is, the shared memory version), META_SIZE (that is, the size of the header memory), the total size of the shared memory, and the addresses of all SLAB linked lists in step 4 (that is, the respective sector linked lists corresponding to each storage area). start address), an empty buckets array (that is, the bucket array), stored in the memory area from 0 to META_SIZE (that is, the header memory), go to step 10;
6.调用系统调用,打开共享内存;6. Call the system call to open the shared memory;
7.读取共享内存前16字节(即对应于共享内存版本和头部内存的大小),获取库版本和META_SIZE信息;7. Read the first 16 bytes of the shared memory (that is, corresponding to the shared memory version and the size of the header memory), and obtain the library version and META_SIZE information;
8.比对库版本(即共享内存的版本与指定内存版本比较)如果不一致则退出,否则继续;8. Compare the library version (that is, the shared memory version is compared with the specified memory version), if it is inconsistent, exit, otherwise continue;
9.读取内存开始到META_SIZE之间的内存(即读取头部内存中的信息),恢复所有元数据信息,其中元数据信息用于以结构化变量的方式访问头部内存中保存的头部信息;9. Read the memory from the beginning of the memory to META_SIZE (that is, read the information in the header memory), and restore all metadata information, where the metadata information is used to access the header saved in the header memory in the form of structured variables Ministry information;
10.完成。10. Done.
针对上述两个模块的【内存操作】阶段,主要流程为:For the [memory operation] stage of the above two modules, the main process is as follows:
1.获得需要操作的key(即键字符串),使用hash算法(即哈希算法),将key转换成一个32位的hash值(即哈希值);1. Obtain the key (ie key string) that needs to be operated, use the hash algorithm (ie hash algorithm), and convert the key into a 32-bit hash value (ie hash value);
2.将hash值除以META(即头部内存)中buckets数组的长度(即指定数组长度),获取余数N;2. Divide the hash value by the length of the buckets array in META (that is, the header memory) (that is, the length of the specified array), and get the remainder N;
3.获取操作类型(即判断调用的本地读写接口的类型),如果是get类型(即读取操作),则转4,否则转5;3. Get the operation type (that is, determine the type of the local read/write interface called), if it is the get type (that is, the read operation), turn to 4, otherwise turn to 5;
4.加读锁并找到buckets数组中的第N个位置的链表(即待遍历链表),遍历这个链表,如果找到该链表中记录的key的值和读取请求中的key值相同,则返回对应的value值(即与键字符串对应的取值),如果遍历完成依然没有找到,返回NO_KEY错误(即键字符串不存在的错误信息)。4. Add a read lock and find the linked list at the Nth position in the buckets array (that is, the linked list to be traversed), and traverse the linked list. If the value of the key recorded in the linked list is found to be the same as the key value in the read request, return If the corresponding value (that is, the value corresponding to the key string) is not found after the traversal is completed, a NO_KEY error (that is, the error message that the key string does not exist) is returned.
5.如果是写入操作,则获取value值(即key对应的取值),计算key和value的总长度TOTAL_LEN(即存储数据的键字符串和取值的总占用空间长度);5. If it is a write operation, obtain the value value (that is, the value corresponding to the key), and calculate the total length TOTAL_LEN of the key and value (that is, the total occupied space length of the key string of the stored data and the value);
6.根据TOTAL_LEN,依次从小到大,计算最合适的SLAB_SIZE;(即将所述总占用空间长度与每个存储区的特定扇区字节数比较,确定保存所述存储数据所需的最小特定扇区字节数);6. According to TOTAL_LEN, from small to large, calculate the most suitable SLAB_SIZE; (that is, compare the length of the total occupied space with the specific sector bytes of each storage area, and determine the minimum specific sector required to save the storage data area bytes);
7.从最合适的SLAB_SIZE对应的链表中,寻找一个空的item(即在所述最小特定扇区字节数对应的存储区对应的扇区链表中查找一个空闲扇区),如果没有找到,直接返回NO_MEM错误(即无可用内存的错误);如果找到,则将key,value复制到这个item的内存区域中(即如果找到空闲扇区则将所述存储数据的键字符串和取值复制到该空闲扇区)。并将这个内存区域加入到buckets数组中的第N个位置的链表中。并且将该扇区标记为已用。返回OK。7. From the linked list corresponding to the most suitable SLAB_SIZE, find an empty item (that is, find a free sector in the sector linked list corresponding to the storage area corresponding to the minimum specific sector byte number), if not found, Return NO_MEM error directly (that is, there is no available memory error); if found, copy the key and value to the memory area of this item (that is, if a free sector is found, copy the key string and value of the stored data) to the free sector). And add this memory area to the linked list at the Nth position in the buckets array. And mark the sector as used. Return OK.
针对持久化模块,其工作方式和流程图可简单描述为图6。For the persistence module, its working mode and flow chart can be simply described as Figure 6.
以上4个模块,除了共享内存是操作系统实现且必须的之外,其他模块可以任意组合并在特定场景下发挥作用,比如开启所有模块时,既可以针对本机需要key-value存储服务的提供远快于跨机器存储的KV服务,同时也可以提供TCP端口,供其他机器的服务使用,两台机器上的应用程序可以通过不同的使用方式共享同一份数据,除此之外,持久化模块会定期将内存中的数据刷写到磁盘中,确保即使在机器掉电等情况下,也不会导致数据丢失。The above four modules, except that the shared memory is implemented and required by the operating system, other modules can be combined arbitrarily and play a role in specific scenarios. For example, when all modules are turned on, the key-value storage service can be provided for the local machine. It is much faster than the KV service stored across machines, and can also provide TCP ports for services of other machines. The applications on the two machines can share the same data in different ways. In addition, the persistence module The data in the memory is periodically flushed to the disk to ensure that data will not be lost even when the machine is powered off.
一个比较典型的使用场景为:一个应用程序A依赖一些KV数据(比如UID和用户名的对应关系),这个应用程序只会读取这些KV数据,而原始的数据,是通过另外有一个应用程序B推送的,在这个场景下,首先开启网络接口模块,申请内存、并监听TCP端口,此时应用程序B就可以开始通过TCP协议推送KV数据,与此同时,应用程序A启动,在没有网络协议损耗的情况下直接通过本地库接口模块读取由B应用程序推送的KV数据,同样的,为了解决机器重新启动导致B程序需要重新推送数据的问题,持久化模块会定时将内存刷写到磁盘,保证在机器重启之后不会丢失数据。A typical usage scenario is: an application A depends on some KV data (such as the correspondence between UID and user name), this application can only read these KV data, and the original data is obtained through another application. Pushed by B, in this scenario, first open the network interface module, apply for memory, and monitor the TCP port. At this time, application B can start to push KV data through the TCP protocol. At the same time, application A starts, and when there is no network In the case of protocol loss, the KV data pushed by application B is directly read through the local library interface module. Similarly, in order to solve the problem that program B needs to re-push data due to machine restart, the persistence module will periodically flush the memory to disk, to ensure that no data will be lost after the machine is restarted.
本发明技术方案具有以下技术效果:在现有技术中,针对Redis、Memcache等KV数据库而言,应用程序与其交互的逻辑大致为如下的1-5步骤:1.应用程序创建与KV数据库得TCP连接;2.应用程序通过TCP连接发送交互请求;3.服务器从TCP连接接收请求;4.服务器处理请求(将请求转换成对内存的读写操作);5.服务器将结果通过TCP连接返回客户端;6.应用程序从TCP连接获取结果。The technical solution of the present invention has the following technical effects: in the prior art, for KV databases such as Redis, Memcache, etc., the logic of the interaction between the application program and it is roughly as follows 1-5 steps: 1. The application program creates a TCP with the KV database. Connection; 2. The application sends interactive requests through the TCP connection; 3. The server receives the request from the TCP connection; 4. The server processes the request (converts the request into a read and write operation to the memory); 5. The server returns the result to the client through the TCP connection 6. The application gets the result from the TCP connection.
而针对本发明技术方案而言,本地应用程序可以通过本地库接口模块,直接对内存的进行读写操作,从而绕过TCP交互的过程,也就是绕过网络协议栈,同时在此基础上支持模块化组装,同一个内存区域可以同时被多个程序和组件共享,也支持TCP协议实现从而允许外部用户访问,也支持根据一定的规则进行持久化操作,即使在机器重启的情况下也可以保证数据不会丢失。For the technical solution of the present invention, the local application program can directly read and write the memory through the local library interface module, thereby bypassing the process of TCP interaction, that is, bypassing the network protocol stack, and on this basis supports Modular assembly, the same memory area can be shared by multiple programs and components at the same time, also supports TCP protocol implementation to allow external users to access, and supports persistent operations according to certain rules, even if the machine is restarted. Data will not be lost.
相比于已经存在的一些KV数据库如Redis、Memcache等,本发明技术方案可以允许程序绕过网络协议栈,直接与KV数据库对应的内存区域进行交互,从而获得极高的性能。Compared with some existing KV databases such as Redis, Memcache, etc., the technical solution of the present invention can allow the program to bypass the network protocol stack and directly interact with the memory area corresponding to the KV database, thereby obtaining extremely high performance.
应该明白,公开的过程中的步骤的特定顺序或层次是示例性方法的实例。基于设计偏好,应该理解,过程中的步骤的特定顺序或层次可以在不脱离本公开的保护范围的情况下得到重新安排。所附的方法权利要求以示例性的顺序给出了各种步骤的要素,并且不是要限于所述的特定顺序或层次。It is understood that the specific order or hierarchy of steps in the disclosed processes is an example of a sample approach. Based upon design preferences, it is understood that the specific order or hierarchy of steps in the processes may be rearranged without departing from the scope of the present disclosure. The accompanying method claims present elements of the various steps in a sample order, and are not meant to be limited to the specific order or hierarchy presented.
在上述的详细描述中,各种特征一起组合在单个的实施方案中,以简化本公开。不应该将这种公开方法解释为反映了这样的意图,即,所要求保护的主题的实施方案需要比清楚地在每个权利要求中所陈述的特征更多的特征。相反,如所附的权利要求书所反映的那样,本发明处于比所公开的单个实施方案的全部特征少的状态。因此,所附的权利要求书特此清楚地被并入详细描述中,其中每项权利要求独自作为本发明单独的优选实施方案。In the foregoing Detailed Description, various features are grouped together in a single embodiment for the purpose of simplifying the disclosure. This method of disclosure should not be interpreted as reflecting an intention that embodiments of the claimed subject matter require more features than are expressly recited in each claim. Rather, as the following claims reflect, present invention lies in less than all features of a single disclosed embodiment. Thus, the following claims are hereby expressly incorporated into the Detailed Description, with each claim standing on its own as a separate preferred embodiment of this invention.
为使本领域内的任何技术人员能够实现或者使用本发明,上面对所公开实施例进行了描述。对于本领域技术人员来说;这些实施例的各种修改方式都是显而易见的,并且本文定义的一般原理也可以在不脱离本公开的精神和保护范围的基础上适用于其它实施例。因此,本公开并不限于本文给出的实施例,而是与本申请公开的原理和新颖性特征的最广范围相一致。The disclosed embodiments are described above to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit and scope of this disclosure. Thus, the present disclosure is not intended to be limited to the embodiments set forth herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
上文的描述包括一个或多个实施例的举例。当然,为了描述上述实施例而描述部件或方法的所有可能的结合是不可能的,但是本领域普通技术人员应该认识到,各个实施例可以做进一步的组合和排列。因此,本文中描述的实施例旨在涵盖落入所附权利要求书的保护范围内的所有这样的改变、修改和变型。此外,就说明书或权利要求书中使用的术语“包含”,该词的涵盖方式类似于术语“包括”,就如同“包括:”在权利要求中用作衔接词所解释的那样。此外,使用在权利要求书的说明书中的任何一个术语“或者”是要表示“非排它性的或者”。The above description includes examples of one or more embodiments. Of course, it is not possible to describe all possible combinations of components or methods in order to describe the above embodiments, but one of ordinary skill in the art will recognize that further combinations and permutations of the various embodiments are possible. Accordingly, the embodiments described herein are intended to cover all such changes, modifications and variations that fall within the scope of the appended claims. Furthermore, with respect to the term "comprising" as used in the specification or claims, the term "comprising" is to be encompassed in a manner similar to the term "comprising," as if "comprising:" was construed as a conjunction in the claims. Furthermore, any use of the term "or" in the specification of the claims is intended to mean a "non-exclusive or."
本领域技术人员还可以了解到本发明实施例列出的各种说明性逻辑块(illustrative logical block),单元,和步骤可以通过电子硬件、电脑软件,或两者的结合进行实现。为清楚展示硬件和软件的可替换性(interchangeability),上述的各种说明性部件(illustrative components),单元和步骤已经通用地描述了它们的功能。这样的功能是通过硬件还是软件来实现取决于特定的应用和整个系统的设计要求。本领域技术人员可以对于每种特定的应用,可以使用各种方法实现所述的功能,但这种实现不应被理解为超出本发明实施例保护的范围。Those skilled in the art may also understand that various illustrative logical blocks (illustrative logical blocks), units, and steps listed in the embodiments of the present invention may be implemented by electronic hardware, computer software, or a combination of the two. To clearly demonstrate the interchangeability of hardware and software, the various illustrative components, units and steps described above have generally described their functions. Whether such functionality is implemented in hardware or software depends on the specific application and overall system design requirements. Those skilled in the art may use various methods to implement the described functions for each specific application, but such implementation should not be construed as exceeding the protection scope of the embodiments of the present invention.
本发明实施例中所描述的各种说明性的逻辑块,或单元都可以通过通用处理器,数字信号处理器,专用集成电路(ASIC),现场可编程门阵列或其它可编程逻辑装置,离散门或晶体管逻辑,离散硬件部件,或上述任何组合的设计来实现或操作所描述的功能。通用处理器可以为微处理器,可选地,该通用处理器也可以为任何传统的处理器、控制器、微控制器或状态机。处理器也可以通过计算装置的组合来实现,例如数字信号处理器和微处理器,多个微处理器,一个或多个微处理器联合一个数字信号处理器核,或任何其它类似的配置来实现。The various illustrative logic blocks, or units described in the embodiments of the present invention can be implemented by general-purpose processors, digital signal processors, application specific integrated circuits (ASICs), field programmable gate arrays or other programmable logic devices, discrete Gate or transistor logic, discrete hardware components, or any combination of the above are designed to implement or operate the functions described. A general-purpose processor may be a microprocessor, or alternatively, the general-purpose processor may be any conventional processor, controller, microcontroller, or state machine. A processor may also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, multiple microprocessors, one or more microprocessors in combination with a digital signal processor core, or any other similar configuration. accomplish.
本发明实施例中所描述的方法或算法的步骤可以直接嵌入硬件、处理器执行的软件模块、或者这两者的结合。软件模块可以存储于RAM存储器、闪存、ROM存储器、EPROM存储器、EEPROM存储器、寄存器、硬盘、可移动磁盘、CD-ROM或本领域中其它任意形式的存储媒介中。示例性地,存储媒介可以与处理器连接,以使得处理器可以从存储媒介中读取信息,并可以向存储媒介存写信息。可选地,存储媒介还可以集成到处理器中。处理器和存储媒介可以设置于ASIC中,ASIC可以设置于用户终端中。可选地,处理器和存储媒介也可以设置于用户终端中的不同的部件中。The steps of the method or algorithm described in the embodiments of the present invention may be directly embedded in hardware, a software module executed by a processor, or a combination of the two. Software modules may be stored in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art. Illustratively, a storage medium may be coupled to the processor such that the processor may read information from, and store information in, the storage medium. Optionally, the storage medium can also be integrated into the processor. The processor and storage medium may be provided in the ASIC, and the ASIC may be provided in the user terminal. Alternatively, the processor and the storage medium may also be provided in different components in the user terminal.
在一个或多个示例性的设计中,本发明实施例所描述的上述功能可以在硬件、软件、固件或这三者的任意组合来实现。如果在软件中实现,这些功能可以存储与电脑可读的媒介上,或以一个或多个指令或代码形式传输于电脑可读的媒介上。电脑可读媒介包括电脑存储媒介和便于使得让电脑程序从一个地方转移到其它地方的通信媒介。存储媒介可以是任何通用或特殊电脑可以接入访问的可用媒体。例如,这样的电脑可读媒体可以包括但不限于RAM、ROM、EEPROM、CD-ROM或其它光盘存储、磁盘存储或其它磁性存储装置,或其它任何可以用于承载或存储以指令或数据结构和其它可被通用或特殊电脑、或通用或特殊处理器读取形式的程序代码的媒介。此外,任何连接都可以被适当地定义为电脑可读媒介,例如,如果软件是从一个网站站点、服务器或其它远程资源通过一个同轴电缆、光纤电缆、双绞线、数字用户线(DSL)或以例如红外、无线和微波等无线方式传输的也被包含在所定义的电脑可读媒介中。所述的碟片(disk)和磁盘(disc)包括压缩磁盘、镭射盘、光盘、DVD、软盘和蓝光光盘,磁盘通常以磁性复制数据,而碟片通常以激光进行光学复制数据。上述的组合也可以包含在电脑可读媒介中。In one or more exemplary designs, the above functions described in the embodiments of the present invention may be implemented in hardware, software, firmware, or any combination of the three. If implemented in software, the functions may be stored on, or transmitted over, a computer-readable medium in the form of one or more instructions or code. Computer-readable media includes computer storage media and communication media that facilitate the transfer of a computer program from one place to another. Storage media can be any available media that a general-purpose or special-purpose computer can access. For example, such computer-readable media may include, but are not limited to, RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage or other magnetic storage devices, or any other device that can be used to carry or store instructions or data structures and Other media in the form of program code that can be read by a general-purpose or special-purpose computer, or a general-purpose or special-purpose processor. Furthermore, any connection is properly defined as a computer-readable medium, for example, if software is transmitted from a web site, server or other remote source over a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL) Or transmitted by wireless means such as infrared, wireless, and microwave are also included in the definition of computer-readable media. The disks and disks include compact disks, laser disks, optical disks, DVDs, floppy disks and blu-ray disks. Disks usually reproduce data magnetically, while discs generally reproduce data optically with lasers. Combinations of the above can also be included in computer readable media.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The specific embodiments described above further describe the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above descriptions are only specific embodiments of the present invention, and are not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111597679.3ACN114398187A (en) | 2021-12-24 | 2021-12-24 | Data storage method and device |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111597679.3ACN114398187A (en) | 2021-12-24 | 2021-12-24 | Data storage method and device |
| Publication Number | Publication Date |
|---|---|
| CN114398187Atrue CN114398187A (en) | 2022-04-26 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111597679.3APendingCN114398187A (en) | 2021-12-24 | 2021-12-24 | Data storage method and device |
| Country | Link |
|---|---|
| CN (1) | CN114398187A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114995762A (en)* | 2022-05-31 | 2022-09-02 | 济南浪潮数据技术有限公司 | Thick backup roll capacity expansion method, device, equipment and storage medium |
| CN117349295A (en)* | 2023-12-04 | 2024-01-05 | 江苏瑞宁信创科技有限公司 | Word frequency statistics method and device |
| CN118035503A (en)* | 2024-04-11 | 2024-05-14 | 福建时代星云科技有限公司 | Method for storing key value pair database |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102651690A (en)* | 2011-02-28 | 2012-08-29 | 国际商业机器公司 | Method and device for controlling shared memory |
| US20160314334A1 (en)* | 2015-04-23 | 2016-10-27 | Shenzhen Huiding Technology Co., Ltd. | Multifunction fingerprint sensor |
| RU2015151065A (en)* | 2015-11-30 | 2017-06-07 | Общество с ограниченной ответственностью "Параллелз" (ООО "Параллелз") | METHOD FOR DATA TRANSFER BETWEEN INTERFACES OF COMPUTER SYSTEM DATA PROCESSING MODULES |
| WO2018049944A1 (en)* | 2016-09-17 | 2018-03-22 | Shenzhen GOODIX Technology Co., Ltd. | Under-screen optical sensor module for on-screen fingerprint sensing |
| US20180322328A1 (en)* | 2017-05-03 | 2018-11-08 | Shenzhen GOODIX Technology Co., Ltd. | Method for determining vital sign information, identity authentication method and apparatus |
| CN109298935A (en)* | 2018-09-06 | 2019-02-01 | 华泰证券股份有限公司 | A kind of method and application of the multi-process single-write and multiple-read without lock shared drive |
| CN110287044A (en)* | 2019-07-02 | 2019-09-27 | 广州虎牙科技有限公司 | Without lock shared drive processing method, device, electronic equipment and readable storage medium storing program for executing |
| CN110502312A (en)* | 2019-08-15 | 2019-11-26 | 东软集团股份有限公司 | A kind of method for reading data, date storage method and device |
| US20200117877A1 (en)* | 2018-08-24 | 2020-04-16 | Shenzhen GOODIX Technology Co., Ltd. | Backlight module, under-screen fingerprint identification apparatus and electronic device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102651690A (en)* | 2011-02-28 | 2012-08-29 | 国际商业机器公司 | Method and device for controlling shared memory |
| US20120221671A1 (en)* | 2011-02-28 | 2012-08-30 | International Business Machines Corporation | Controlling Shared Memory |
| US20160314334A1 (en)* | 2015-04-23 | 2016-10-27 | Shenzhen Huiding Technology Co., Ltd. | Multifunction fingerprint sensor |
| RU2015151065A (en)* | 2015-11-30 | 2017-06-07 | Общество с ограниченной ответственностью "Параллелз" (ООО "Параллелз") | METHOD FOR DATA TRANSFER BETWEEN INTERFACES OF COMPUTER SYSTEM DATA PROCESSING MODULES |
| WO2018049944A1 (en)* | 2016-09-17 | 2018-03-22 | Shenzhen GOODIX Technology Co., Ltd. | Under-screen optical sensor module for on-screen fingerprint sensing |
| US20180322328A1 (en)* | 2017-05-03 | 2018-11-08 | Shenzhen GOODIX Technology Co., Ltd. | Method for determining vital sign information, identity authentication method and apparatus |
| US20200117877A1 (en)* | 2018-08-24 | 2020-04-16 | Shenzhen GOODIX Technology Co., Ltd. | Backlight module, under-screen fingerprint identification apparatus and electronic device |
| CN109298935A (en)* | 2018-09-06 | 2019-02-01 | 华泰证券股份有限公司 | A kind of method and application of the multi-process single-write and multiple-read without lock shared drive |
| CN110287044A (en)* | 2019-07-02 | 2019-09-27 | 广州虎牙科技有限公司 | Without lock shared drive processing method, device, electronic equipment and readable storage medium storing program for executing |
| CN110502312A (en)* | 2019-08-15 | 2019-11-26 | 东软集团股份有限公司 | A kind of method for reading data, date storage method and device |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114995762A (en)* | 2022-05-31 | 2022-09-02 | 济南浪潮数据技术有限公司 | Thick backup roll capacity expansion method, device, equipment and storage medium |
| CN117349295A (en)* | 2023-12-04 | 2024-01-05 | 江苏瑞宁信创科技有限公司 | Word frequency statistics method and device |
| CN117349295B (en)* | 2023-12-04 | 2024-02-13 | 江苏瑞宁信创科技有限公司 | Word frequency statistics method and device |
| CN118035503A (en)* | 2024-04-11 | 2024-05-14 | 福建时代星云科技有限公司 | Method for storing key value pair database |
| CN118035503B (en)* | 2024-04-11 | 2024-06-28 | 福建时代星云科技有限公司 | A storage method for key-value database |
| Publication | Publication Date | Title |
|---|---|---|
| CN114398187A (en) | Data storage method and device | |
| JP5309043B2 (en) | Storage system and method for duplicate data deletion in storage system | |
| JP5082310B2 (en) | Data migration apparatus and program | |
| US8239648B2 (en) | Reclamation of thin provisioned disk storage | |
| US6192444B1 (en) | Method and system for providing additional addressable functional space on a disk for use with a virtual data storage subsystem | |
| CN110531940A (en) | Video file processing method and processing device | |
| CN110109873B (en) | File management method for message queue | |
| US8001323B2 (en) | Network storage system, management method therefor, and control program product therefor | |
| US20080040539A1 (en) | Method and system for writing and reading application data | |
| EP2510434B1 (en) | Consistency without ordering dependency | |
| US11221989B2 (en) | Tape image reclaim in hierarchical storage systems | |
| US20070156763A1 (en) | Storage management system and method thereof | |
| US8140886B2 (en) | Apparatus, system, and method for virtual storage access method volume data set recovery | |
| US20060136779A1 (en) | Object-based storage device with low process load and control method thereof | |
| CN112463753A (en) | Block chain data storage method, system, equipment and readable storage medium | |
| JP6197816B2 (en) | Storage system, storage management method, and computer program | |
| CN118672516A (en) | Data storage method, device, storage medium and computer program product | |
| JP2004265110A (en) | Metadata arrangement method, program and disk device | |
| US20220156230A1 (en) | Distributed file system servicing random-access operations | |
| JP4394467B2 (en) | Storage system, server apparatus, and preceding copy data generation method | |
| CN116301602B (en) | Data recording or reading method, device, collection equipment, vehicle and medium | |
| US11762603B2 (en) | Storing modified or unmodified portions of a file based on tape loading | |
| WO2023169164A1 (en) | Method and apparatus for restoring application program, and computer device and storage medium | |
| JP4060890B2 (en) | A file system primitive that allows I/O requests to be reprocessed by multiple drivers in a layered driver I/O system. | |
| CN114490855A (en) | Data import method and device |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| TA01 | Transfer of patent application right | ||
| TA01 | Transfer of patent application right | Effective date of registration:20230419 Address after:Room 501-502, 5/F, Sina Headquarters Scientific Research Building, Block N-1 and N-2, Zhongguancun Software Park, Dongbei Wangxi Road, Haidian District, Beijing, 100193 Applicant after:Sina Technology (China) Co.,Ltd. Address before:100193 7th floor, scientific research building, Sina headquarters, plot n-1, n-2, Zhongguancun Software Park, Dongbei Wangxi Road, Haidian District, Beijing, 100193 Applicant before:Sina.com Technology (China) Co.,Ltd. |