In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Talk about the process ID and MongoDB _ id primary key of the operating system
In the distributed system, the merging of data becomes normal, and the database in the stand-alone system can use self-increasing ID as the primary key, which is simple and easy. However, in distributed systems, there are great difficulties in data merging. The selection of data primary key has become a big problem. A general solution is to use GUID as the primary key. GUID as a database primary key also has two disadvantages. One is that some database systems do not have a GUID type and have to replace it with a string of 32 bits (hexadecimal representation of 16Byte bytes). Second, Guid does not have the order rule, so it is very inefficient in sorting.
In MongoDB, each document has a _ id, which uses a generation algorithm to ensure that the ID is not duplicated in a distributed case. Part of the algorithm is process ID. It takes up two bytes and supports a total of 65535 process numbers (0xFFFF). When we look at the operating system API (Windows and Linux), we find that the process ID is an integer, so will there be a problem with MogonDB's algorithm?
View the maximum process allowed by the system ID in Linux:
# cat / proc/sys/kernel/pid_max32768
As you can see, the maximum allowed process ID in Linux is 32768. Another question, the process ID integer, and is incremented, is this number enough?
In fact, it is impossible to run so many processes at the same time in Linux. When a process ends, the process's ID is idle. The idle ID was not reclaimed by the Linux system in time, but began to be rolled back when the PID continued to increase to the maximum. That is, when you create a new process, look for the available process number, and then assign the process number to the new process.
Linux is fine. What about Windows?
The process ID in Windows is actually a pseudo index of the global handle table PspCidTable. For why it is a pseudo index, see the following description:
The handle table of a process contains pointers to all those objects that have been opened by the process. An object handle is a "pseudo index" used to retrieve the handle table. The achillis series of articles have analyzed the handle table mechanism very thoroughly, but the source of "handle steps by 4" is unknown. After investigation, the root causes are as follows:
Typedefstruct _ EXHANDLE
{
Union
{
Struct
{
ULONG TagBits:2
ULONG Index:30
}
HANDLE GenericHandleOverlay
# define HANLE_VALUE_INC 4
ULONG_PTR Value
}
} EXHANDLE,*PEXHANDLE
This structure is used to define the handle type. The lower 2-bit TagBits is the flag bit Windows for other purposes, so a lower 2-bit handle value makes no sense as a handle table index itself, so it is equal to a multiple of 4. With the above analysis, naturally, when fetching the handle table item with the handle value for the index, the handle value must be / 4. Therefore, the handle value used in the program can not be directly used to index the handle table, so there is the term "pseudo index".
The global handle table of Windows has 65535 locations, so the windows system can only provide a maximum of 65536Universe 16384 available handles. (if you keep opening the process ID in the program but do not close the unused process handle in time, it will cause the system to slow down and crash.)
How to view the process ID under Windows:
1. Press the ctrl+alt+ delete key to bring up the taskbar manager, click View-Select column-tick in front of PID in the pop-up window, take you and make sure that in the taskbar manager process, PID is the process number of the process!
two。 Start-run-enter: cmd in the dialog box and enter enter-enter tasklist in the pop-up console and all processes will appear. Again, under PID is the process number!
Well, the process representation in the primary key of MogonDB is not a problem in Windows.
As for the headers, the primary key in MongoDB claims that the strategy is still very effective. The MongoDB primary key is represented as follows:
4 bits: timestamp (accurate to seconds) 3 digits: machine name hash value 2 digits: process ID3 bits: automatically increased sequence values.
In this scheme, we can use the strategy of generating database primary key as our own information system for reference. But there is one thing the author needs to do, and the hash of the 3-digit machine name may be duplicated.
In an environment, if you can guarantee that the machine name does not repeat, it is difficult to guarantee that the three bytes after the machine name hash will not repeat. Of course, when there are only a few or a dozen machines, the possibility of this conflict is relatively low.
Even if the hash of the machine name is repeated, it happens that the process ID of the two machines is the same, and the same self-increasing sequence value is encountered in the same second, so that the resulting ID will be repeated. Look, you can calculate how low the probability is.
reference.
Http://www.newsmth.net/nForum/#!article/KernelTech/59502
Http://www.cnblogs.com/Thriving-Country/archive/2011/09/18/2180143.html
Http://zhidao.baidu.com/question/147564693.html
Http://blog.csdn.net/scorpio3k/article/details/5835614
~ ~ THE END~~
Yin Shuguang
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.