One of the memory database R & D logs. The strange problem of shared memory

Source: Internet
Author: User

One of the memory database R & D logs. The strange problem of shared memory

Papayas

20091211

I. Sequencing

The database is very complex in the application system. Taking ORACLE database as an example, its complexity is no less than that of any
Operating System. Writing a memory database by yourself is just a fantasy. But this time I want Tan Yi
Tan, develop a memory database. It not only includes the back-end control call part (which should be implemented using C/C ++ ),
You are also preparing to write a webconsole (using Java for implementation ).

This database is simple, practical, and has outstanding performance. This is the goal,
It's not to say that we want to bring down oracle or the like, but it's just a crazy dream. It's not up to you for 30 years. As
How much time can be achieved, it can only be said to be slow, because it is only intended to take advantage of the spare time.

In this regard, I was actually prepared before, but I wrote something very bad than oracle.
The first version is not similar! Think about it. This version is named 2.0. It seems a bit like Oracle,
Because the first version sold to users is 2.0.

 

Ii. Shared Memory

Like Oracle, the shared memory is used to store database data. But today's test accidentally discovered
One problem is that shared memory cannot be shared. The problem lies in this "part "!

Symptom description:

1. Start the memory test program

[Oracle @ windows memdb2.]./testtablevar 123
[Err] memory: open: no such file or directory
Size, Max, hwm, headsize, free, reused, used
------------------------------------------------------------
10000000,244 1, 1, 58644, 1, 0, 0
ID, key, hash, start, Len, pre, next
------------------------------------------------------------
0, 0, 0, 0, 0, 0, 0
1, 0, 0, 1, 2441, 0, 0
C>
As shown above, the shared memory has been created here:

2. view shared memory information in Linux

[Oracle @ windows memdb2] IPCS
------ Shared memory segments --------
Key shmid owner perms bytes nattch status
0x00000123 524288 Oracle 640 500000000 0

3. Run the program again.

[Oracle @ windows memdb2] $./testtablevar123
Size, Max, hwm, headsize, free, reused, used
------------------------------------------------------------
10000000,244 1, 1, 58644, 1, 0, 0
ID, key, hash, start, Len, pre, next
------------------------------------------------------------
0, 0, 0, 0, 0, 0, 0
1, 0, 0, 0, 0, 0, 0
C>
Note that some memory information is lost.

There is currently no intrinsic way for a process to ensure exclusive
Access to a shared memory segment. asserting both ipc_creat and
Ipc_excl in shmflg only ensures (on success) that a new shared memory
Segment will be created, it doesn' t imply exclusive access to the seg-
Ment.

Strange ~

4. Do not exit on the Interface above. directly enter the command R, p, q

C> r
C> P
ID, key, hash, start, Len, pre, next
------------------------------------------------------------
0, 0, 0, 0, 0, 0, 0
1, 0, 0, 1, 2441, 0, 0
C> q

R is used to re-initialize the memory (without calling any memory call, only for logic processing), P prints Information

5. Run the program again.

[Oracle @ windows memdb2] $./testtablevar123
Size, Max, hwm, headsize, free, reused, used
------------------------------------------------------------
10000000,244 1, 1, 58644, 1, 0, 0
ID, key, hash, start, Len, pre, next
------------------------------------------------------------
0, 0, 0, 0, 0, 0, 0
1, 0, 0, 1, 2441, 0, 0
C>

Everything is normal. It's okay to change the program to query the memory!

6. Cause

When I wrote it here, I suddenly knew the problem was located, that is, the memory address problem! Share
All pointers must be reset during memory usage!

Void tablevar: open (void * _ ADDR ){

This-> m_phead = (ttablevarhead *) _ ADDR;

}

Must be changed

Void tablevar: open (void * _ ADDR ){

This-> m_phead = (ttablevarhead *) _ ADDR;
 
This-> m_phead-> DATA = (char *) _ ADDR + this-> m_phead-> headsize;
This-> m_phead-> chain = (ttablevarheadchain *) (char *) This-> m_phead + sizeof (ttablevarhead ));
 
}

All memory table classes are in this issue! Let's take a closer look at the previous program as if
Similar problems have also occurred. Writing logs in time is a very good way, which has caused me to do it for a long time!

Iii. Postscript

The R & D path must be full of thorns, but the key to the problem lies in summing up and recording to enrich the individual's
Design ideas and extend the knowledge of software. In the end, it must be far more than a different database.
More.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.