1998Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] Persistant storage.... My current idea. -->
<!--X-From-R13: X Q Znjerapr <pynjNhaqre.rate.ftv.pbz> -->
<!--X-Date: Wed, 01 Apr 1998 22:58:15 +0000 -->
<!--X-Message-Id: 199804012258.OAA103164#under,engr.sgi.com -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: Pine.LNX.3.96.980328222126.666A&#45;100000#shamen,cyberhighway.net -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev] Persistant storage.... My current idea.</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:claw#under,engr.sgi.com">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00006.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00008.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00008.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00009.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00007">Author</A>
&nbsp;|&nbsp;<A HREF="#00007">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00007">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev] Persistant storage.... My current idea.</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI>
<LI><em>Subject</em>: Re: [MUD-Dev] Persistant storage.... My current idea. </LI>
<LI><em>From</em>: J C Lawrence &lt;<A HREF="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</A>&gt;</LI>
<LI><em>Date</em>: Wed, 01 Apr 1998 14:58:09 -0800</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
On Sat, 28 Mar 1998 21:53:09 PST8PDT 
Ben Greear&lt;greear#cyberhighway,net&gt; wrote:

&gt; I'm currently planning on using one file, with certain blocks
&gt; allocated within it for objects.  It will basically be a linked list
&gt; represented as a file.

&gt; I'll have headers that point the the seek position of the next and
&gt; previous element in the file.  It will also keep track of the used
&gt; and total space allocated for that element.

&gt; If I need to update, and it's too big, it will be moved to the end
&gt; of the file, and the previous element will get it's space.  (I'll
&gt; deal with boundary cases, sufice it to say.)

&gt; Now, this reeks of inneficiency when trying to look up an object
&gt; based on some key (object number in my case, probably 8 bytes ).

&gt; However, I'm going to create a hash table at boot time to link an
&gt; object id with the seek position of that object in the file.  I
&gt; believe this should give me as quick access as I can expect.

A very simple cheat which performs very nicely is to do something as
follows:

  Every record in the DB is identified by a unique record # of a
signed integer type.

  The DB consists of two files, the database itself, and an index.

  The index file is an array of the following structures:

    struct {
      off_t record_pos;   // Offset of the record in the DB
      size_t record_len;  // Length of the record in the DB
    }

  The N'th structure in the index file, located by seeking to an
offset of (N *sizeof (struct)) and then reading sizeof (struct) bytes, 
holds the data for the record in the DB with a record number of N.

  Seeking to offset record_pos in the DB file and reading record_len
bytes will get you the wrapped contents of that record.

  The DB file is an amorphous binary blob of no particular pattern.
It contains records of variable length which follow a particular
pattern:

    struct {
      unsigned char beg_signature[16];
      signed long record_num;
      size_t record_len;
      unsigned char data[1]; // the actual contents of the record,
                             // record_len bytes long.
      off_t next_record;     // Offset of next record in DB
      unsigned char end_signature[16];
    }

  This pattern is the "wrapped" pattern.  The first record_len bytes
of the data[] array are the actual data contents of the record.

  There is reason behind the signatures and the like.  Look at tdbm
and YOODA for working models.  The base reason here is so that the
index file can be reconstructed from the DB file, and so that gross
format corruption can be detected.

  New records are added into either the first free space in the DB
file that is large enough to hold them, or some "best fit" equivalent.
As old records are deleted this opens "spaces" that new records (with
potentially very different record numbers) will be inserted into.
Order has no importance in the DB file -- that is what the index file
is for.  

  Of course eventually your DB will be peppered with such small spaces
which are too small for new records -- then you pack the DB.
  

&gt; Some other things: I'll have objects unique across the universe,
&gt; even different servers.  (Each server will be assigned an ID, and
&gt; each object within that server will have a unique ID.  So, given
&gt; both ID's, I can guarantee uniqueness.)

You need to look at Cool -- it did exactly this with some success.

&gt; PS.  I hope the fact that the last message I saw was about a change
&gt; in the mailing list software isn't a bad sign!!

I now have a dedicated 'net connection at home.  In celebration I'm
moving the list to Petidomo (see www.petidomo.com), and adding
searchable web archives of past list traffic (yes, email addresses
will be munged), and a backing FTP site.  This transfer was supposed
to be happening today.  It didn't and it won't, not today.  Sorry.
RSN.

-- 
J C Lawrence                               Internet: claw#null,net
(Contractor)                               Internet: coder#ibm,net
---------(*)                     Internet: claw#under,engr.sgi.com
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...

</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00009" HREF="msg00009.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>
<ul compact><li><em>From:</em> Ben Greear &lt;greear#cyberhighway,net&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00006.html">Re: [MUD-Dev] World Persistence, flat files v/s DB v/s ??</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00008.html">Monthly FAQ Posting</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00008.html">Monthly FAQ Posting</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00009.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00007"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00007"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>[MUD-Dev] Re: MUD Development Digest</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<LI><strong><A NAME="00346" HREF="msg00346.html">[MUD-Dev] Re: MUD Development Digest</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Thu 23 Apr 1998, 02:56 GMT
<UL>
<LI><strong><A NAME="00360" HREF="msg00360.html">[MUD-Dev] Re: MUD Development Digest</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Thu 23 Apr 1998, 05:58 GMT
</LI>
</UL>
</LI>
</ul>
</ul>
</LI>
<LI><strong><A NAME="00014" HREF="msg00014.html">OT: This is a test of a system config change.</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Sat 04 Apr 1998, 05:40 GMT
<LI><strong><A NAME="00008" HREF="msg00008.html">Monthly FAQ Posting</A></strong>, 
Ling <a href="mailto:K.L.Lo-94#student,lboro.ac.uk">K.L.Lo-94#student,lboro.ac.uk</a>, Thu 02 Apr 1998, 14:27 GMT
<LI><strong><A NAME="00007" HREF="msg00007.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Wed 01 Apr 1998, 22:58 GMT
<UL>
<LI><strong><A NAME="00009" HREF="msg00009.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Fri 03 Apr 1998, 09:11 GMT
<UL>
<LI><strong><A NAME="00010" HREF="msg00010.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Fri 03 Apr 1998, 17:57 GMT
<UL>
<LI><strong><A NAME="00013" HREF="msg00013.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sat 04 Apr 1998, 01:32 GMT
<UL>
<LI><strong><A NAME="00049" HREF="msg00049.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Tue 07 Apr 1998, 16:56 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>