Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Chapter 20 Exercises 787


29% and 59% to the clock time over no locking and that mandatory locking adds about
another 15% over advisory locking.

Exercises


20.1 The locking in_db_dodeleteis somewhat conservative. For example, we could allow
moreconcurrency by not write locking the free list until we really need to; that is, the call
to writew_lock could be moved between the calls to _db_writedat and
_db_readptr.What happens if we do this?
20.2 Ifdb_nextrecdid not read lock the free list and a recordthat it was reading was also in
the process of being deleted, describe howdb_nextreccould return the correct key but
an all-blank (hence incorrect) data record. (Hint: Look at_db_dodelete.)
20.3 At the end of Section 20.8, we described the locking performed by_db_writeidxand
_db_writedat.Wesaid that this locking didn’t interferewith other readers and writers
except those making calls todb_store.Isthis true if mandatory locking is being used?
20.4 How would you integrate thefsyncfunction into this database library?
20.5 Indb_store, we write the data recordbeforethe index record. What happens if you do it
in the opposite order?
20.6 Create a new database and write some number of records to the database. Write a
program that callsdb_nextrecto read each record in the database, and call_db_hashto
calculate the hash value for each record. Printahistogram of the number of records on
each hash chain. Is the hashing function in_db_hashadequate?
20.7 Modify the database functions so that the number of hash chains in the index file can be
specified when the database is created.
20.8 Comparethe performance of the database functions when the database is (a) on the same
host as the test program and (b) on a different host accessed via NFS. Does the record
locking provided by the database library still work?
20.9 The database reuses free list records only if the sizes of the key buffer and data buffer
match the needed sizes exactly.Modify the database to allow larger buffer sizes on the free
list to satisfy the request. How do you have to change the persistent format of the database
to support this feature?
20.10 After implementing a solution to Exercise 20.9, write a tool to convert one database format
to the other.
Free download pdf