2004-07-13 23:48:20 +00:00
|
|
|
/*---
|
|
|
|
This software is copyrighted by the Regents of the University of
|
|
|
|
California, and other parties. The following terms apply to all files
|
|
|
|
associated with the software unless explicitly disclaimed in
|
|
|
|
individual files.
|
|
|
|
|
|
|
|
The authors hereby grant permission to use, copy, modify, distribute,
|
|
|
|
and license this software and its documentation for any purpose,
|
|
|
|
provided that existing copyright notices are retained in all copies
|
|
|
|
and that this notice is included verbatim in any distributions. No
|
|
|
|
written agreement, license, or royalty fee is required for any of the
|
|
|
|
authorized uses. Modifications to this software may be copyrighted by
|
|
|
|
their authors and need not follow the licensing terms described here,
|
|
|
|
provided that the new terms are clearly indicated on the first page of
|
|
|
|
each file where they apply.
|
|
|
|
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
|
|
|
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
|
|
|
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
|
|
|
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
|
|
|
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
|
|
|
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
|
|
|
|
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
|
|
|
U.S. government, the Government shall have only "Restricted Rights" in
|
|
|
|
the software and related documentation as defined in the Federal
|
|
|
|
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
|
|
|
acquiring the software on behalf of the Department of Defense, the
|
|
|
|
software shall be classified as "Commercial Computer Software" and the
|
|
|
|
Government shall have only "Restricted Rights" as defined in Clause
|
|
|
|
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
|
|
|
authors grant the U.S. Government and others acting in its behalf
|
|
|
|
permission to use and distribute the software in accordance with the
|
|
|
|
terms specified in this license.
|
|
|
|
---*/
|
|
|
|
|
2007-07-18 20:09:14 +00:00
|
|
|
/** @file
|
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
@todo check_page should judiciously avoid stasis_page_lsn_ptr()
|
2007-07-18 20:09:14 +00:00
|
|
|
*/
|
2009-04-14 20:21:05 +00:00
|
|
|
#include "../check_includes.h"
|
2004-07-13 23:48:20 +00:00
|
|
|
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/page.h>
|
|
|
|
#include <stasis/page/slotted.h>
|
|
|
|
#include <stasis/blobManager.h>
|
2007-06-11 21:36:57 +00:00
|
|
|
#include <stasis/bufferManager.h>
|
|
|
|
#include <stasis/transactional.h>
|
2008-04-13 04:02:57 +00:00
|
|
|
#include <stasis/latches.h>
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
#include <sched.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define LOG_NAME "check_page.log"
|
|
|
|
|
|
|
|
#define RECORD_SIZE sizeof(int)
|
|
|
|
|
|
|
|
pthread_mutex_t random_mutex;
|
|
|
|
static lsn_t lsn;
|
|
|
|
static pthread_mutex_t lsn_mutex;
|
2004-07-30 01:28:39 +00:00
|
|
|
|
|
|
|
static void * multiple_simultaneous_pages ( void * arg_ptr) {
|
|
|
|
Page * p = (Page*)arg_ptr;
|
|
|
|
int i;
|
|
|
|
lsn_t this_lsn;
|
2004-08-17 01:46:17 +00:00
|
|
|
short j;
|
2004-07-30 01:28:39 +00:00
|
|
|
int first = 1;
|
|
|
|
int k;
|
|
|
|
recordid rid[100];
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
for(i = 0; i < 10000; i++) {
|
2009-04-14 20:21:05 +00:00
|
|
|
pthread_mutex_lock(&lsn_mutex);
|
2004-07-30 01:28:39 +00:00
|
|
|
lsn++;
|
2007-06-07 21:53:09 +00:00
|
|
|
this_lsn = lsn;
|
2008-09-28 03:11:24 +00:00
|
|
|
readlock(p->rwlatch,0);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_page_lsn_read(p) < this_lsn);
|
2008-09-28 03:11:24 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-30 01:28:39 +00:00
|
|
|
pthread_mutex_unlock(&lsn_mutex);
|
|
|
|
|
2008-09-28 05:50:59 +00:00
|
|
|
if(!first) {
|
2004-07-30 01:28:39 +00:00
|
|
|
for(k = 0; k < 100; k++) {
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2008-09-28 05:50:59 +00:00
|
|
|
stasis_record_read(1, p, rid[k], (byte*)&j);
|
|
|
|
assert((j + 1) == i + k);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_free(-1, p, rid[k]);
|
|
|
|
stasis_page_lsn_write(-1, p, this_lsn);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2008-09-28 05:50:59 +00:00
|
|
|
sched_yield();
|
2004-07-30 01:28:39 +00:00
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
}
|
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
first = 0;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
for(k = 0; k < 100; k++) {
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2007-10-02 00:18:33 +00:00
|
|
|
rid[k] = stasis_record_alloc_begin(-1,p,sizeof(short));
|
2007-06-07 21:53:09 +00:00
|
|
|
if(rid[k].size == INVALID_SLOT) { // Is rid[k] == NULLRID?
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_compact(p);
|
|
|
|
rid[k] = stasis_record_alloc_begin(-1,p,sizeof(short));
|
2007-06-07 21:53:09 +00:00
|
|
|
}
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_alloc_done(-1,p,rid[k]);
|
2008-02-19 21:56:32 +00:00
|
|
|
short * buf = (short*)stasis_record_write_begin(-1,p,rid[k]);
|
2007-06-07 21:53:09 +00:00
|
|
|
*buf = i+k;
|
2008-02-19 21:56:32 +00:00
|
|
|
stasis_record_write_done(-1,p,rid[k],(byte*)buf);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_page_lsn_write(-1, p, this_lsn);
|
|
|
|
assert(stasis_page_lsn_read(p) >= this_lsn);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-30 01:28:39 +00:00
|
|
|
sched_yield();
|
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
}
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-06 06:08:09 +00:00
|
|
|
static void* fixed_worker_thread(void * arg_ptr) {
|
|
|
|
Page * p = (Page*)arg_ptr;
|
|
|
|
int i;
|
|
|
|
lsn_t this_lsn;
|
|
|
|
int first = 1;
|
|
|
|
recordid rid;
|
|
|
|
|
|
|
|
for(i = 0; i < 100; i++) {
|
|
|
|
pthread_mutex_lock(&lsn_mutex);
|
|
|
|
this_lsn = lsn;
|
|
|
|
lsn++;
|
|
|
|
pthread_mutex_unlock(&lsn_mutex);
|
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2004-10-06 06:08:09 +00:00
|
|
|
if(! first ) {
|
2008-02-19 21:56:32 +00:00
|
|
|
int * buf = (int*)stasis_record_read_begin(-1,p,rid);
|
|
|
|
assert(((*buf) + 1) == i);
|
|
|
|
stasis_record_read_done(-1,p,rid,(byte*)buf);
|
2007-06-07 21:53:09 +00:00
|
|
|
}
|
2004-10-06 06:08:09 +00:00
|
|
|
first = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
rid = stasis_record_alloc_begin(-1, p, sizeof(int));
|
|
|
|
stasis_record_alloc_done(-1, p, rid);
|
2008-02-19 21:56:32 +00:00
|
|
|
int * buf = (int*)stasis_record_write_begin(-1,p,rid);
|
|
|
|
*buf = i;
|
|
|
|
stasis_record_write_done(-1,p,rid,(byte*)buf);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_page_lsn_write(-1, p,lsn);
|
|
|
|
assert(stasis_page_lsn_read(p) >= this_lsn);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-10-06 06:08:09 +00:00
|
|
|
sched_yield();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
static void* worker_thread(void * arg_ptr) {
|
2004-07-14 20:49:18 +00:00
|
|
|
Page * p = (Page*)arg_ptr;
|
2004-07-13 23:48:20 +00:00
|
|
|
int i;
|
|
|
|
lsn_t this_lsn;
|
|
|
|
int j;
|
|
|
|
int first = 1;
|
|
|
|
recordid rid;
|
2004-07-23 20:21:44 +00:00
|
|
|
for(i = 0; i < 10000; i++) {
|
2004-07-13 23:48:20 +00:00
|
|
|
pthread_mutex_lock(&lsn_mutex);
|
2006-03-20 23:11:46 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
this_lsn = lsn;
|
|
|
|
lsn++;
|
2006-03-20 23:11:46 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
pthread_mutex_unlock(&lsn_mutex);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
|
|
|
if(! first ) {
|
2008-09-28 05:50:59 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_read(1, p, rid, (byte*)&j);
|
2004-07-13 23:48:20 +00:00
|
|
|
assert((j + 1) == i);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_free(-1, p, rid);
|
|
|
|
stasis_page_lsn_write(-1, p, this_lsn);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-13 23:48:20 +00:00
|
|
|
sched_yield();
|
2007-06-07 21:53:09 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
first = 0;
|
2006-03-20 23:11:46 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
// @todo In check_page, a condition variable would be more efficient...
|
|
|
|
writelock(p->rwlatch,0);
|
2007-10-02 00:18:33 +00:00
|
|
|
if(stasis_record_freespace(-1, p) < sizeof(int)) {
|
2006-03-20 23:11:46 +00:00
|
|
|
first = 1;
|
|
|
|
} else {
|
2007-10-02 00:18:33 +00:00
|
|
|
rid = stasis_record_alloc_begin(-1, p, sizeof(int));
|
|
|
|
stasis_record_alloc_done(-1, p, rid);
|
|
|
|
int * buf = (int*)stasis_record_write_begin(-1, p, rid);
|
|
|
|
stasis_page_lsn_write(-1,p,this_lsn);
|
2007-06-07 21:53:09 +00:00
|
|
|
*buf = i;
|
2008-02-19 21:56:32 +00:00
|
|
|
stasis_record_write_done(-1,p,rid,(byte*)buf);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_page_lsn_read(p) >= this_lsn);
|
2006-03-20 23:11:46 +00:00
|
|
|
}
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-13 23:48:20 +00:00
|
|
|
sched_yield();
|
|
|
|
|
|
|
|
}
|
2006-03-20 23:11:46 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-14 20:21:05 +00:00
|
|
|
@test
|
2004-07-13 23:48:20 +00:00
|
|
|
|
|
|
|
just run one the worker_thread function once to make sure that it passes
|
|
|
|
without interference from other threads.
|
|
|
|
|
|
|
|
The number of slots allocated by the page tests is too low to check
|
|
|
|
that freed space is recovered.
|
|
|
|
|
|
|
|
*/
|
|
|
|
START_TEST(pageNoThreadTest)
|
|
|
|
{
|
2004-07-14 20:49:18 +00:00
|
|
|
Page * p;
|
2004-07-13 23:48:20 +00:00
|
|
|
|
|
|
|
pthread_mutex_init(&lsn_mutex, NULL);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
Tinit();
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(-1, 0);
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2009-07-20 17:42:43 +00:00
|
|
|
stasis_page_slotted_initialize_page(p);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-14 20:49:18 +00:00
|
|
|
worker_thread(p);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
2006-04-07 03:40:40 +00:00
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2004-07-20 00:15:17 +00:00
|
|
|
|
2007-03-07 06:45:28 +00:00
|
|
|
releasePage(p);
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
Tdeinit();
|
|
|
|
|
2007-03-07 06:45:28 +00:00
|
|
|
pthread_mutex_destroy(&lsn_mutex);
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
/**
|
|
|
|
@test
|
|
|
|
*/
|
|
|
|
|
|
|
|
START_TEST(pageCheckMacros) {
|
|
|
|
Page p;
|
|
|
|
byte buffer[PAGE_SIZE];
|
|
|
|
memset(buffer, -1, PAGE_SIZE);
|
|
|
|
|
|
|
|
p.memAddr = buffer;
|
|
|
|
|
|
|
|
lsn_t lsn = 5;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(&p) = lsn;
|
|
|
|
*stasis_page_type_ptr(&p) = 10;
|
2009-07-20 17:42:43 +00:00
|
|
|
*stasis_page_slotted_freespace_ptr(&p) = 15;
|
|
|
|
*stasis_page_slotted_numslots_ptr(&p) = 20;
|
|
|
|
*stasis_page_slotted_slot_ptr(&p, 0) = 30;
|
|
|
|
*stasis_page_slotted_slot_ptr(&p, 1) = 35;
|
|
|
|
*stasis_page_slotted_slot_ptr(&p, 40) = 40;
|
|
|
|
*stasis_page_slotted_slot_length_ptr(&p, 0) = 31;
|
|
|
|
*stasis_page_slotted_slot_length_ptr(&p, 1) = 36;
|
|
|
|
*stasis_page_slotted_slot_length_ptr(&p, 40) = 41;
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_byte_ptr_from_start(&p, 0) = 50;
|
|
|
|
*stasis_page_byte_ptr_from_start(&p, 1) = 51;
|
|
|
|
*stasis_page_byte_ptr_from_start(&p, 2) = 52;
|
|
|
|
*stasis_page_byte_ptr_from_start(&p, 3) = 53;
|
|
|
|
*stasis_page_byte_ptr_from_start(&p, 4) = 54;
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(*stasis_page_lsn_ptr(&p) == lsn);
|
|
|
|
assert(*stasis_page_type_ptr(&p) == 10);
|
|
|
|
//assert(end_of_usable_space_ptr(&p) == stasis_page_type_ptr(&p));
|
2009-07-20 17:42:43 +00:00
|
|
|
assert(*stasis_page_slotted_freespace_ptr(&p) == 15);
|
|
|
|
assert(*stasis_page_slotted_numslots_ptr(&p) == 20);
|
|
|
|
assert(*stasis_page_slotted_slot_ptr(&p, 0) == 30);
|
|
|
|
assert(*stasis_page_slotted_slot_ptr(&p, 1) == 35);
|
|
|
|
assert(*stasis_page_slotted_slot_ptr(&p, 40) == 40);
|
|
|
|
assert(*stasis_page_slotted_slot_length_ptr(&p, 0) == 31);
|
|
|
|
assert(*stasis_page_slotted_slot_length_ptr(&p, 1) == 36);
|
|
|
|
assert(*stasis_page_slotted_slot_length_ptr(&p, 40) == 41);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(*stasis_page_byte_ptr_from_start(&p, 0) == 50);
|
|
|
|
assert(*stasis_page_byte_ptr_from_start(&p, 1) == 51);
|
|
|
|
assert(*stasis_page_byte_ptr_from_start(&p, 2) == 52);
|
|
|
|
assert(*stasis_page_byte_ptr_from_start(&p, 3) == 53);
|
|
|
|
assert(*stasis_page_byte_ptr_from_start(&p, 4) == 54);
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2007-08-20 16:04:44 +00:00
|
|
|
} END_TEST
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2007-08-20 16:04:44 +00:00
|
|
|
static void assertRecordCountSizeType(int xid, Page *p, int count, int size, int type) {
|
|
|
|
int foundRecords = 0;
|
|
|
|
|
2007-10-02 00:18:33 +00:00
|
|
|
recordid it = stasis_record_first(xid,p);
|
2007-08-20 16:04:44 +00:00
|
|
|
assert(it.size != INVALID_SLOT);
|
|
|
|
do {
|
|
|
|
foundRecords++;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_length_read(xid,p,it) == size);
|
|
|
|
assert(stasis_record_type_read(xid,p,it) == type);
|
2007-08-20 16:04:44 +00:00
|
|
|
it.size = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_length_read(xid,p,it) == size);
|
|
|
|
assert(stasis_record_type_read(xid,p,it) == type);
|
2007-08-20 16:04:44 +00:00
|
|
|
it.size = INVALID_SLOT;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_length_read(xid,p,it) == size);
|
|
|
|
assert(stasis_record_type_read(xid,p,it) == type);
|
|
|
|
it = stasis_record_next(xid,p,it);
|
2007-08-20 16:04:44 +00:00
|
|
|
} while(it.size != INVALID_SLOT);
|
|
|
|
|
|
|
|
assert(foundRecords == count);
|
|
|
|
assert(it.page == NULLRID.page);
|
|
|
|
assert(it.slot == NULLRID.slot);
|
|
|
|
assert(it.size == NULLRID.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void checkPageIterators(int xid, Page *p,int record_count) {
|
2007-10-02 00:18:33 +00:00
|
|
|
recordid first = stasis_record_alloc_begin(xid, p, sizeof(int64_t));
|
|
|
|
stasis_record_alloc_done(xid,p,first);
|
2007-08-20 16:04:44 +00:00
|
|
|
|
|
|
|
for(int i = 1; i < record_count; i++) {
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_alloc_done(xid,p,stasis_record_alloc_begin(xid,p,sizeof(int64_t)));
|
2007-08-20 16:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assertRecordCountSizeType(xid, p, record_count, sizeof(int64_t), NORMAL_SLOT);
|
|
|
|
|
|
|
|
|
2009-07-07 19:20:22 +00:00
|
|
|
if(p->pageType == SLOTTED_PAGE) {
|
2007-08-20 16:04:44 +00:00
|
|
|
recordid other = first;
|
|
|
|
other.slot = 3;
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_record_free(xid,p,other);
|
2007-08-20 16:04:44 +00:00
|
|
|
assertRecordCountSizeType(xid, p, record_count-1, sizeof(int64_t), NORMAL_SLOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
@test
|
|
|
|
|
|
|
|
Check functions used to iterate over pages
|
|
|
|
|
|
|
|
XXX this should also test indirect pages.
|
|
|
|
*/
|
|
|
|
START_TEST(pageRecordSizeTypeIteratorTest) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
|
|
|
pageid_t pid = TpageAlloc(xid);
|
|
|
|
|
|
|
|
Page * p = loadPage(xid,pid);
|
|
|
|
writelock(p->rwlatch,0);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2009-07-20 17:42:43 +00:00
|
|
|
stasis_page_slotted_initialize_page(p);
|
2007-08-20 16:04:44 +00:00
|
|
|
|
|
|
|
checkPageIterators(xid,p,10);
|
|
|
|
|
|
|
|
unlock(p->rwlatch);
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2007-08-20 16:04:44 +00:00
|
|
|
pid = TpageAlloc(xid);
|
2009-05-30 02:23:17 +00:00
|
|
|
releasePage(p);
|
2007-08-20 16:04:44 +00:00
|
|
|
p = loadPage(xid,pid);
|
|
|
|
writelock(p->rwlatch,0);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_fixed_initialize_page(p,sizeof(int64_t),0);
|
2007-08-20 16:04:44 +00:00
|
|
|
|
|
|
|
checkPageIterators(xid,p,10);
|
|
|
|
|
|
|
|
unlock(p->rwlatch);
|
2009-05-30 02:23:17 +00:00
|
|
|
releasePage(p);
|
2007-08-20 16:04:44 +00:00
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
Tdeinit();
|
2004-07-30 01:28:39 +00:00
|
|
|
} END_TEST
|
|
|
|
/**
|
2009-04-14 20:21:05 +00:00
|
|
|
@test
|
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
Page test that allocates multiple records
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
*/
|
|
|
|
START_TEST(pageNoThreadMultPageTest)
|
|
|
|
{
|
|
|
|
Page * p;
|
|
|
|
/* p->id = 0;*/
|
|
|
|
|
|
|
|
|
|
|
|
pthread_mutex_init(&lsn_mutex, NULL);
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(-1, 1);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2007-06-07 21:53:09 +00:00
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-06-07 21:53:09 +00:00
|
|
|
|
|
|
|
writelock(p->rwlatch,0);
|
2009-07-20 17:42:43 +00:00
|
|
|
stasis_page_slotted_initialize_page(p);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-07-30 01:28:39 +00:00
|
|
|
multiple_simultaneous_pages(p);
|
2006-04-07 03:40:40 +00:00
|
|
|
// Normally, you would call pageWriteLSN() to update the LSN. This
|
|
|
|
// is a hack, since Tdeinit() will crash if it detects page updates
|
|
|
|
// that are off the end of the log..
|
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2006-04-07 03:40:40 +00:00
|
|
|
|
2004-08-17 01:46:17 +00:00
|
|
|
releasePage(p);
|
2006-04-07 03:40:40 +00:00
|
|
|
|
2004-08-17 01:46:17 +00:00
|
|
|
/* unlock(p->loadlatch); */
|
2004-07-30 01:28:39 +00:00
|
|
|
|
2006-04-07 03:40:40 +00:00
|
|
|
|
2004-07-30 01:28:39 +00:00
|
|
|
Tdeinit();
|
2007-03-07 06:45:28 +00:00
|
|
|
pthread_mutex_destroy(&lsn_mutex);
|
2004-07-30 01:28:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
/**
|
2004-07-13 23:48:20 +00:00
|
|
|
Check the page implementation in the multi-threaded case.
|
|
|
|
*/
|
|
|
|
START_TEST(pageThreadTest) {
|
|
|
|
|
2004-07-26 20:37:04 +00:00
|
|
|
#define THREAD_COUNT 10
|
2004-07-13 23:48:20 +00:00
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
pthread_mutex_init(&random_mutex, NULL);
|
2004-07-26 20:37:04 +00:00
|
|
|
pthread_mutex_init(&lsn_mutex, NULL);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
fail_unless(1, NULL);
|
2004-07-13 23:48:20 +00:00
|
|
|
Tinit();
|
2004-07-23 20:21:44 +00:00
|
|
|
Tdeinit();
|
|
|
|
Tinit();
|
|
|
|
fail_unless(1, NULL);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
Page * p = loadPage(-1, 2);
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2009-07-20 17:42:43 +00:00
|
|
|
stasis_page_slotted_initialize_page(p);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-06-07 21:53:09 +00:00
|
|
|
|
2004-07-23 20:21:44 +00:00
|
|
|
fail_unless(1, NULL);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
2004-07-14 20:49:18 +00:00
|
|
|
pthread_create(&workers[i], NULL, worker_thread, p);
|
2004-07-13 23:48:20 +00:00
|
|
|
}
|
2004-07-23 20:21:44 +00:00
|
|
|
fail_unless(1, NULL);
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
}
|
2004-07-20 00:15:17 +00:00
|
|
|
|
2004-10-06 06:08:09 +00:00
|
|
|
/* unlock(p->loadlatch); */
|
2006-04-07 03:40:40 +00:00
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2004-10-06 06:08:09 +00:00
|
|
|
releasePage(p);
|
2004-07-20 00:15:17 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
Tdeinit();
|
|
|
|
|
2007-03-07 06:45:28 +00:00
|
|
|
pthread_mutex_destroy(&lsn_mutex);
|
|
|
|
pthread_mutex_destroy(&random_mutex);
|
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
} END_TEST
|
|
|
|
|
|
|
|
|
2009-04-14 20:21:05 +00:00
|
|
|
/**
|
2004-11-24 23:23:01 +00:00
|
|
|
@test
|
|
|
|
*/
|
2004-10-06 06:08:09 +00:00
|
|
|
START_TEST(fixedPageThreadTest) {
|
|
|
|
pthread_t workers[THREAD_COUNT];
|
|
|
|
int i;
|
|
|
|
pthread_mutex_init(&random_mutex, NULL);
|
|
|
|
pthread_mutex_init(&lsn_mutex, NULL);
|
|
|
|
Tinit();
|
2005-02-10 03:51:09 +00:00
|
|
|
Page * p = loadPage(-1, 2);
|
2007-06-07 21:53:09 +00:00
|
|
|
writelock(p->rwlatch,0);
|
2008-02-19 21:56:32 +00:00
|
|
|
memset(p->memAddr, 0, PAGE_SIZE);
|
2007-10-02 00:18:33 +00:00
|
|
|
stasis_fixed_initialize_page(p, sizeof(int), 0);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-06-07 21:53:09 +00:00
|
|
|
|
2004-10-06 06:08:09 +00:00
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_create(&workers[i], NULL, fixed_worker_thread, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < THREAD_COUNT; i++) {
|
|
|
|
pthread_join(workers[i], NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-07 03:40:40 +00:00
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2004-10-06 06:08:09 +00:00
|
|
|
releasePage(p);
|
2006-04-07 03:40:40 +00:00
|
|
|
Tdeinit();
|
2007-03-07 06:45:28 +00:00
|
|
|
pthread_mutex_destroy(&lsn_mutex);
|
|
|
|
pthread_mutex_destroy(&random_mutex);
|
2004-10-06 06:08:09 +00:00
|
|
|
} END_TEST
|
|
|
|
|
2009-07-07 20:03:52 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
START_TEST(pageCheckSlotTypeTest) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
recordid slot = Talloc(xid, sizeof(int));
|
|
|
|
recordid fixedRoot = TarrayListAlloc(xid, 2, 10, 10);
|
|
|
|
recordid blob = Talloc(xid, PAGE_SIZE * 2);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
Page * p = loadPage(-1, slot.page);
|
2007-06-07 21:53:09 +00:00
|
|
|
readlock(p->rwlatch, 0);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_type_read(xid, p, slot) == NORMAL_SLOT);
|
|
|
|
assert(stasis_record_length_read(xid, p, slot) == sizeof(int));
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-11-24 23:23:01 +00:00
|
|
|
releasePage(p);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
|
|
|
/** @todo the use of the fixedRoot recordid to check getRecordType is
|
2004-11-24 23:23:01 +00:00
|
|
|
a bit questionable, but should work. */
|
2009-04-14 20:21:05 +00:00
|
|
|
p = loadPage(-1, fixedRoot.page);
|
2005-02-10 03:51:09 +00:00
|
|
|
|
2009-07-07 20:03:52 +00:00
|
|
|
readlock(p->rwlatch, 0);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_type_read(xid, p, fixedRoot) == NORMAL_SLOT);
|
2009-07-07 20:03:52 +00:00
|
|
|
unlock(p->rwlatch);
|
|
|
|
releasePage(p);
|
2007-06-07 21:53:09 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
fixedRoot.slot = 1;
|
2007-10-02 00:18:33 +00:00
|
|
|
|
2009-07-07 20:03:52 +00:00
|
|
|
assert(TrecordType(xid, fixedRoot) == NORMAL_SLOT);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(-1, blob.page);
|
2007-06-07 21:53:09 +00:00
|
|
|
readlock(p->rwlatch, 0);
|
2007-10-02 00:18:33 +00:00
|
|
|
int type = stasis_record_type_read(xid, p, blob);
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
|
|
|
assert(type == BLOB_SLOT);
|
2009-04-14 20:21:05 +00:00
|
|
|
releasePage(p);
|
2007-06-07 21:53:09 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
recordid bad;
|
|
|
|
bad.page = slot.page;
|
|
|
|
bad.slot = slot.slot + 10;
|
|
|
|
bad.size = 4;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2005-02-10 03:51:09 +00:00
|
|
|
p = loadPage(xid, bad.page);
|
2007-06-07 21:53:09 +00:00
|
|
|
readlock(p->rwlatch, 0);
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_type_read(xid, p, bad) == INVALID_SLOT);
|
2004-11-24 23:23:01 +00:00
|
|
|
bad.size = 100000;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_type_read(xid, p, bad) == INVALID_SLOT);
|
2007-06-07 21:53:09 +00:00
|
|
|
/** recordGetType now ignores the size field, so this (correctly) returns SLOTTED_RECORD */
|
2004-11-24 23:23:01 +00:00
|
|
|
bad.slot = slot.slot;
|
2007-10-02 00:18:33 +00:00
|
|
|
assert(stasis_record_type_read(xid, p, bad) == NORMAL_SLOT);
|
2006-04-07 03:40:40 +00:00
|
|
|
p->LSN = 0;
|
2007-10-02 00:18:33 +00:00
|
|
|
*stasis_page_lsn_ptr(p) = p->LSN;
|
2007-06-07 21:53:09 +00:00
|
|
|
unlock(p->rwlatch);
|
2004-11-24 23:23:01 +00:00
|
|
|
releasePage(p);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
Tcommit(xid);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
2004-12-01 01:26:25 +00:00
|
|
|
/**
|
|
|
|
@test unit test for TrecordType
|
|
|
|
*/
|
|
|
|
START_TEST(pageTrecordTypeTest) {
|
|
|
|
Tinit();
|
|
|
|
int xid = Tbegin();
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
recordid slot = Talloc(xid, sizeof(int));
|
|
|
|
recordid fixedRoot = TarrayListAlloc(xid, 2, 10, 10);
|
|
|
|
recordid blob = Talloc(xid, PAGE_SIZE * 2);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(TrecordType(xid, slot) == NORMAL_SLOT);
|
2009-04-14 20:21:05 +00:00
|
|
|
assert(TrecordType(xid, fixedRoot) == NORMAL_SLOT);
|
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
fixedRoot.slot = 1;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
int type = TrecordType(xid, blob);
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(type == BLOB_SLOT);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
recordid bad;
|
|
|
|
bad.page = slot.page;
|
|
|
|
bad.slot = slot.slot + 10;
|
|
|
|
bad.size = 4;
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(TrecordType(xid, bad) == INVALID_SLOT);
|
2004-12-01 01:26:25 +00:00
|
|
|
bad.size = 100000;
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(TrecordType(xid, bad) == INVALID_SLOT);
|
2005-01-28 03:32:17 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
bad.slot = slot.slot;
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(TrecordType(xid, bad) == NORMAL_SLOT);
|
2005-01-31 01:29:52 +00:00
|
|
|
/* Try to trick TrecordType by allocating a record that's the
|
|
|
|
same length as the slot used by blobs. */
|
|
|
|
recordid rid2 = Talloc(xid, sizeof(blob_record_t));
|
2007-06-07 21:53:09 +00:00
|
|
|
assert(TrecordType(xid, rid2) == NORMAL_SLOT);
|
2005-01-31 01:29:52 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
Tcommit(xid);
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-12-01 01:26:25 +00:00
|
|
|
Tdeinit();
|
|
|
|
} END_TEST
|
|
|
|
|
2004-11-24 23:23:01 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
Suite * check_suite(void) {
|
|
|
|
Suite *s = suite_create("page");
|
|
|
|
/* Begin a new test */
|
|
|
|
TCase *tc = tcase_create("pagethreads");
|
2005-03-10 03:19:04 +00:00
|
|
|
tcase_set_timeout(tc, 0); // disable timeouts
|
2004-07-13 23:48:20 +00:00
|
|
|
/* Sub tests are added, one per line, here */
|
|
|
|
|
2007-08-20 16:04:44 +00:00
|
|
|
tcase_add_test(tc, pageRecordSizeTypeIteratorTest);
|
2004-07-30 01:28:39 +00:00
|
|
|
tcase_add_test(tc, pageCheckMacros);
|
2004-11-24 23:23:01 +00:00
|
|
|
tcase_add_test(tc, pageCheckSlotTypeTest);
|
2004-12-01 01:26:25 +00:00
|
|
|
tcase_add_test(tc, pageTrecordTypeTest);
|
2004-07-30 01:28:39 +00:00
|
|
|
tcase_add_test(tc, pageNoThreadMultPageTest);
|
2004-07-13 23:48:20 +00:00
|
|
|
tcase_add_test(tc, pageNoThreadTest);
|
2004-07-30 01:28:39 +00:00
|
|
|
tcase_add_test(tc, pageThreadTest);
|
2004-10-06 06:08:09 +00:00
|
|
|
tcase_add_test(tc, fixedPageThreadTest);
|
2004-07-13 23:48:20 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------- */
|
2009-04-14 20:21:05 +00:00
|
|
|
|
2004-07-13 23:48:20 +00:00
|
|
|
tcase_add_checked_fixture(tc, setup, teardown);
|
|
|
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "../check_setup.h"
|