YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/* Test av isam-databas: stor test */
#ifndef USE_MY_FUNC /* We want to be able to dbug this !! */ #define USE_MY_FUNC #endif #include"maria_def.h" #include"trnman.h" #include <m_ctype.h> #include <my_bit.h> #include"ma_checkpoint.h"
for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ; if (j != 0)
{
snprintf((char*) key, sizeof(key), "%6d",j); if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT))
{
printf("can't find key1: \"%s\"\n", (char*) key); goto err;
} if (bcmp(read_record+keyinfo[0].seg[0].start,
key, keyinfo[0].seg[0].length))
{
printf("Found wrong record when searching for key: \"%s\"; Found \"%.*s\"\n",
key, keyinfo[0].seg[0].length,
read_record+keyinfo[0].seg[0].start); goto err2;
} if (use_blob)
{
ulong blob_length; if (i & 1)
put_blob_in_record(record2+blob_pos,&blob_buffer, &blob_length); else
bmove(record2+blob_pos, read_record+blob_pos, 4 + sizeof(char*));
} if (skip_update) continue; if (maria_update(file,read_record,record2))
{ if (my_errno != HA_ERR_FOUND_DUPP_KEY || key3[n3] == 0)
{
printf("error: %d; can't update:\nFrom: \"%s\"\nTo: \"%s\"\n",
my_errno,read_record,record2); goto err;
} if (verbose)
printf("Double key when tried to update:\nFrom: \"%s\"\nTo: \"%s\"\n",record,record2);
} else
{
key1[atoi((char*) read_record+keyinfo[0].seg[0].start)]--;
key3[atoi((char*) read_record+keyinfo[2].seg[0].start)]=0;
key1[n1]++; key3[n3]=1;
update++;
}
}
} if (testflag == 4) goto end; if (checkpoint == 4 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err;
for (i=999, dupp_keys=j=0 ; i>0 ; i--)
{ if (key1[i] > dupp_keys)
{
dupp_keys=key1[i]; j=i;
}
}
snprintf((char*) key, sizeof(key), "%6d",j);
start=keyinfo[0].seg[0].start;
length=keyinfo[0].seg[0].length; if (dupp_keys)
{ if (!silent)
printf("- Same key: first - next -> last - prev -> first\n");
DBUG_PRINT("progpos",("first - next -> last - prev -> first")); if (verbose) printf(" Using key: \"%s\" Keys: %d\n",key,dupp_keys);
if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT)) goto err; if (maria_rsame(file,read_record2,-1)) goto err; if (memcmp(read_record,read_record2,reclength) != 0)
{
printf("maria_rsame didn't find same record\n"); goto err2;
}
info.recpos=maria_position(file); if (maria_rfirst(file,read_record2,0) ||
maria_rsame_with_pos(file,read_record2,0,info.recpos) ||
memcmp(read_record,read_record2,reclength) != 0)
{
printf("maria_rsame_with_pos didn't find same record\n"); goto err2;
}
{ int skr;
info.recpos= maria_position(file);
skr= maria_rnext(file,read_record2,0); if ((skr && my_errno != HA_ERR_END_OF_FILE) ||
maria_rprev(file,read_record2,0) ||
memcmp(read_record,read_record2,reclength) != 0 ||
info.recpos != maria_position(file))
{
printf("maria_rsame_with_pos lost position\n"); goto err;
}
}
ant=1; while (maria_rnext(file,read_record2,0) == 0 &&
memcmp(read_record2+start,key,length) == 0) ant++; if (ant != dupp_keys)
{
printf("next: Found: %d keys of %d\n",ant,dupp_keys); goto err2;
}
ant=0; while (maria_rprev(file,read_record3,0) == 0 &&
bcmp(read_record3+start,key,length) == 0) ant++; if (ant != dupp_keys)
{
printf("prev: Found: %d records of %d\n",ant,dupp_keys); goto err2;
}
/* Check of maria_rnext_same */ if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT)) goto err;
ant=1; while (!maria_rnext_same(file,read_record3) && ant < dupp_keys+10)
ant++; if (ant != dupp_keys || my_errno != HA_ERR_END_OF_FILE)
{
printf("maria_rnext_same: Found: %d records of %d\n",ant,dupp_keys); goto err2;
}
}
if (!silent)
printf("- All keys: first - next -> last - prev -> first\n");
DBUG_PRINT("progpos",("All keys: first - next -> last - prev -> first"));
ant=1; if (maria_rfirst(file,read_record,0))
{
printf("Can't find first record\n"); goto err;
} while ((error=maria_rnext(file,read_record3,0)) == 0 && ant < write_count+10)
ant++; if (ant != write_count - opt_delete || error != HA_ERR_END_OF_FILE)
{
printf("next: I found: %d records of %d (error: %d)\n",
ant, write_count - opt_delete, error); goto err;
} if (maria_rlast(file,read_record2,0) ||
bcmp(read_record2,read_record3,reclength))
{
printf("Can't find last record\n");
DBUG_DUMP("record2", read_record2, reclength);
DBUG_DUMP("record3", read_record3, reclength); goto err2;
}
ant=1; while (maria_rprev(file,read_record3,0) == 0 && ant < write_count+10)
ant++; if (ant != write_count - opt_delete)
{
printf("prev: I found: %d records of %d\n",ant,write_count); goto err2;
} if (bcmp(read_record,read_record3,reclength))
{
printf("Can't find first record\n"); goto err2;
}
if (!silent)
printf("- Test if: Read first - next - prev - prev - next == first\n");
DBUG_PRINT("progpos",("- Read first - next - prev - prev - next == first")); if (maria_rfirst(file,read_record,0) ||
maria_rnext(file,read_record3,0) ||
maria_rprev(file,read_record3,0) ||
maria_rprev(file,read_record3,0) == 0 ||
maria_rnext(file,read_record3,0)) goto err; if (bcmp(read_record,read_record3,reclength) != 0)
printf("Can't find first record\n");
if (!silent)
printf("- Test if: Read last - prev - next - next - prev == last\n");
DBUG_PRINT("progpos",("Read last - prev - next - next - prev == last")); if (maria_rlast(file,read_record2,0) ||
maria_rprev(file,read_record3,0) ||
maria_rnext(file,read_record3,0) ||
maria_rnext(file,read_record3,0) == 0 ||
maria_rprev(file,read_record3,0)) goto err; if (bcmp(read_record2,read_record3,reclength))
printf("Can't find last record\n"); #ifdef NOT_ANYMORE if (!silent)
puts("- Test read key-part");
strmov(key2,key); for(i=strlen(key2) ; i-- > 1 ;)
{
key2[i]=0;
/* The following row is just to catch some bugs in the key code */
bzero((char*) file->lastkey,file->s->base.max_key_length*2); if (maria_rkey(file,read_record,0,key2,(uint) i,HA_READ_PREFIX)) goto err; if (bcmp(read_record+start,key,(uint) i))
{
puts("Didn't find right record"); goto err2;
}
} #endif if (dupp_keys > 2)
{ if (!silent)
printf("- Read key (first) - next - delete - next -> last\n");
DBUG_PRINT("progpos",("first - next - delete - next -> last")); if (maria_rkey(file,read_record,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT)) goto err; if (maria_rnext(file,read_record3,0)) goto err; if (maria_delete(file,read_record3)) goto err;
opt_delete++;
ant=1; while (maria_rnext(file,read_record3,0) == 0 &&
bcmp(read_record3+start,key,length) == 0) ant++; if (ant != dupp_keys-1)
{
printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-1); goto err2;
}
} if (dupp_keys>4)
{ if (!silent)
printf("- Read last of key - prev - delete - prev -> first\n");
DBUG_PRINT("progpos",("last - prev - delete - prev -> first")); if (maria_rprev(file,read_record3,0)) goto err; if (maria_rprev(file,read_record3,0)) goto err; if (maria_delete(file,read_record3)) goto err;
opt_delete++;
ant=1; while (maria_rprev(file,read_record3,0) == 0 &&
bcmp(read_record3+start,key,length) == 0) ant++; if (ant != dupp_keys-2)
{
printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-2); goto err2;
}
} if (dupp_keys > 6)
{ if (!silent)
printf("- Read first - delete - next -> last\n");
DBUG_PRINT("progpos",("first - delete - next -> last")); if (maria_rkey(file,read_record3,0,key,HA_WHOLE_KEY,HA_READ_KEY_EXACT)) goto err; if (maria_delete(file,read_record3)) goto err;
opt_delete++;
ant=1; if (maria_rnext(file,read_record,0)) goto err; /* Skall finnas poster */ while (maria_rnext(file,read_record3,0) == 0 &&
bcmp(read_record3+start,key,length) == 0) ant++; if (ant != dupp_keys-3)
{
printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-3); goto err2;
}
if (!silent)
printf("- Read last - delete - prev -> first\n");
DBUG_PRINT("progpos",("last - delete - prev -> first")); if (maria_rprev(file,read_record3,0)) goto err; if (maria_delete(file,read_record3)) goto err;
opt_delete++;
ant=0; while (maria_rprev(file,read_record3,0) == 0 &&
bcmp(read_record3+start,key,length) == 0) ant++; if (ant != dupp_keys-4)
{
printf("next: I can only find: %d keys of %d\n",ant,dupp_keys-4); goto err2;
}
}
if (!silent)
puts("- Test if: Read rrnd - same");
DBUG_PRINT("progpos",("Read rrnd - same"));
maria_scan_init(file); for (i=0 ; i < write_count ; i++)
{ int tmp; if ((tmp= maria_scan(file,read_record)) &&
tmp != HA_ERR_END_OF_FILE &&
tmp != HA_ERR_RECORD_DELETED)
{
printf("Got error %d when scanning table\n", tmp); break;
} if (!tmp)
{ /* Remember position to last found row */
info.recpos= maria_position(file);
bmove(read_record2,read_record,reclength);
}
}
maria_scan_end(file); if (i != write_count && i != write_count - opt_delete)
{
printf("Found wrong number of rows while scanning table\n"); goto err2;
}
if (maria_rsame_with_pos(file,read_record,0,info.recpos)) goto err; if (bcmp(read_record,read_record2,reclength) != 0)
{
printf("maria_rsame_with_pos didn't find same record\n"); goto err2;
}
for (i=MY_MIN(2,keys) ; i-- > 0 ;)
{ if (maria_rsame(file,read_record2,(int) i)) goto err; if (bcmp(read_record,read_record2,reclength) != 0)
{
printf("maria_rsame didn't find same record\n"); goto err2;
}
} if (!silent)
puts("- Test maria_records_in_range");
maria_status(file,&info,HA_STATUS_VARIABLE); for (i=0 ; i < info.keys ; i++)
{
key_range min_key, max_key; if (maria_rfirst(file,read_record,(int) i) ||
maria_rlast(file,read_record2,(int) i)) goto err;
copy_key(file,(uint) i, read_record, key);
copy_key(file,(uint) i, read_record2, key2);
min_key.key= key;
min_key.keypart_map= HA_WHOLE_KEY;
min_key.flag= HA_READ_KEY_EXACT;
max_key.key= key2;
max_key.keypart_map= HA_WHOLE_KEY;
max_key.flag= HA_READ_AFTER_KEY;
range_records= maria_records_in_range(file,(int) i, &min_key, &max_key,
&pages); if (range_records < info.records*8/10 ||
range_records > info.records*12/10)
{
printf("maria_records_range returned %ld; Should be about %ld\n",
(long) range_records,(long) info.records); goto err2;
} if (verbose)
{
printf("maria_records_range returned %ld; Exact is %ld (diff: %4.2g %%)\n",
(long) range_records, (long) info.records,
labs((long) range_records - (long) info.records)*100.0/
info.records);
}
} for (i=0 ; i < 5 ; i++)
{ for (j=rnd(1000)+1 ; j>0 && key1[j] == 0 ; j--) ; for (k=rnd(1000)+1 ; k>0 && key1[k] == 0 ; k--) ; if (j != 0 && k != 0)
{
key_range min_key, max_key; if (j > k)
swap_variables(int, j, k);
snprintf((char*) key, sizeof(key), "%6d",j);
snprintf((char*) key2, sizeof(key2), "%6d",k);
min_key.key= key;
min_key.keypart_map= HA_WHOLE_KEY;
min_key.flag= HA_READ_AFTER_KEY;
max_key.key= key2;
max_key.keypart_map= HA_WHOLE_KEY;
max_key.flag= HA_READ_BEFORE_KEY;
range_records= maria_records_in_range(file, 0, &min_key, &max_key,
&pages);
records=0; for (j++ ; j < k ; j++)
records+=key1[j]; if ((long) range_records < (long) records*6/10-2 ||
(long) range_records > (long) records*14/10+2)
{
printf("maria_records_range for key: %d returned %lu; Should be about %lu\n",
i, (ulong) range_records, (ulong) records); goto err2;
} if (verbose && records)
{
printf("maria_records_range returned %lu; Exact is %lu (diff: %4.2g %%)\n",
(ulong) range_records, (ulong) records,
labs((long) range_records-(long) records)*100.0/records);
}
}
}
if (!silent)
printf("- maria_info\n");
maria_status(file,&info,HA_STATUS_VARIABLE | HA_STATUS_CONST); if (info.records != write_count-opt_delete ||
info.deleted > opt_delete + update || info.keys != keys)
{
puts("Wrong info from maria_info");
printf("Got: records: %lu delete: %lu i_keys: %d\n",
(ulong) info.records, (ulong) info.deleted, info.keys); goto err2;
} if (verbose)
{ char buff[80];
get_date(buff,sizeof(buff),3,info.create_time);
printf("info: Created %s\n",buff);
get_date(buff,sizeof(buff),3,info.check_time);
printf("info: checked %s\n",buff);
get_date(buff,sizeof(buff),3,info.update_time);
printf("info: Modified %s\n",buff);
}
maria_panic(HA_PANIC_WRITE);
maria_panic(HA_PANIC_READ); if (maria_is_changed(file))
puts("Warning: maria_is_changed reported that datafile was changed");
if (!silent)
printf("- maria_extra(CACHE) + maria_rrnd.... + maria_extra(NO_CACHE)\n"); if (maria_reset(file) || maria_extra(file,HA_EXTRA_CACHE,0))
{ if (do_locking || (!use_blob && !pack_fields))
{
puts("got error from maria_extra(HA_EXTRA_CACHE)"); goto err;
}
}
ant=0;
maria_scan_init(file); while ((error= maria_scan(file,record)) != HA_ERR_END_OF_FILE &&
ant < write_count + 10)
ant+= error ? 0 : 1;
maria_scan_end(file); if (ant != write_count-opt_delete)
{
printf("scan with cache: I can only find: %d records of %d\n",
ant,write_count-opt_delete);
maria_scan_end(file); goto err2;
} if (maria_extra(file,HA_EXTRA_NO_CACHE,0))
{
puts("got error from maria_extra(HA_EXTRA_NO_CACHE)");
maria_scan_end(file); goto err;
}
maria_scan_end(file);
ant=0;
maria_scan_init(file); while ((error=maria_scan(file,record)) != HA_ERR_END_OF_FILE &&
ant < write_count + 10)
ant+= error ? 0 : 1; if (ant != write_count-opt_delete)
{
printf("scan with cache: I can only find: %d records of %d\n",
ant,write_count-opt_delete);
maria_scan_end(file); goto err2;
}
maria_scan_end(file);
if (testflag == 5) goto end; if (checkpoint == 5 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err;
if (!silent)
printf("- Removing keys\n");
DBUG_PRINT("progpos",("Removing keys"));
lastpos = HA_OFFSET_ERROR; /* DBUG_POP(); */
maria_reset(file);
found_parts=0;
maria_scan_init(file); while ((error= maria_scan(file,read_record)) != HA_ERR_END_OF_FILE)
{
info.recpos=maria_position(file); if (lastpos >= info.recpos && lastpos != HA_OFFSET_ERROR)
{
printf("maria_rrnd didn't advance filepointer; old: %ld, new: %ld\n",
(long) lastpos, (long) info.recpos); goto err2;
}
lastpos=info.recpos; if (error == 0)
{ if (opt_delete == (uint) remove_count) /* While testing */ goto end; if (rnd(2) == 1 && maria_rsame(file,read_record,-1))
{
printf("can't find record %lx\n",(long) info.recpos); goto err;
} if (use_blob)
{
ulong blob_length,pos;
uchar *ptr;
memcpy(&ptr, read_record+blob_pos+4, sizeof(ptr));
blob_length= uint4korr(read_record+blob_pos); for (pos=0 ; pos < blob_length ; pos++)
{ if (ptr[pos] != (uchar) (blob_length+pos))
{
printf("Found blob with wrong info at %ld\n",(long) lastpos);
maria_scan_end(file);
my_errno= 0; goto err2;
}
}
} if (maria_delete(file,read_record))
{
printf("can't delete record: %6.6s, delete_count: %d\n",
read_record, opt_delete);
maria_scan_end(file); goto err;
}
opt_delete++;
} else
found_parts++;
} if (my_errno != HA_ERR_END_OF_FILE && my_errno != HA_ERR_RECORD_DELETED)
printf("error: %d from maria_rrnd\n",my_errno); if (write_count != opt_delete)
{
printf("Deleted only %d of %d records (%d parts)\n",opt_delete,write_count,
found_parts);
maria_scan_end(file); goto err2;
} if (testflag == 6) goto end; if (checkpoint == 6 && ma_checkpoint_execute(CHECKPOINT_MEDIUM, FALSE)) goto err;
end:
maria_scan_end(file); if (die_in_middle_of_transaction)
{ /* As commit record is not done, UNDO entries needs to be rolled back */ switch (die_in_middle_of_transaction) { case1: /* Flushchangeddataandindexpagesgotodisk Thatwillalsoflushlog.RecoverywillskipREDOsandapplyUNDOs.
*/
_ma_flush_table_files(file, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX,
FLUSH_RELEASE, FLUSH_RELEASE); break; case2: /* Justflushlog.Pagesarelikelytonotbeondisk.Recoverywill thenexecuteREDOsandUNDOs.
*/ if (translog_flush(file->trn->undo_lsn)) goto err; break; case3: /* Flushnothing.Pagesandlogarelikelytonotbeondisk.Recovery willthendonothing.
*/ break; case4: /* Flushchangeddatapagesgotodisk.Changedindexpagesarenot flushed.RecoverywillskipsomeREDOsandapplyUNDOs.
*/
_ma_flush_table_files(file, MARIA_FLUSH_DATA, FLUSH_RELEASE,
FLUSH_RELEASE); /* Wehavetoflushlogseparatelyastheredoforthelastkeypage maynotbeflushed
*/ if (translog_flush(file->trn->undo_lsn)) goto err; break;
}
printf("Dying on request without maria_commit()/maria_close()\n");
sf_leaking_memory= 1; /* no memory leak reports here */ exit(0);
} if (maria_commit(file)) goto err; if (maria_close(file))
{
file= 0; goto err;
}
file= 0;
multi_update_pagecache_stats();
maria_panic(HA_PANIC_CLOSE); /* Should close log */ if (!silent)
{
printf("\nFollowing test have been made:\n");
printf("Write records: %d\nUpdate records: %d\nSame-key-read: %d\nDelete records: %d\n", write_count,update,dupp_keys,opt_delete); if (rec_pointer_size)
printf("Record pointer size: %d\n",rec_pointer_size);
printf("maria_block_size: %u\n", maria_block_size); if (write_cacheing)
puts("Key cache resized"); if (write_cacheing)
puts("Write cacheing used"); if (write_cacheing)
puts("quick mode"); if (async_io && do_locking)
puts("Asyncron io with locking used"); elseif (do_locking)
puts("Locking used"); if (use_blob)
puts("blobs used");
printf("key cache status: \n\
blocks used:%10lu\n\ not flushed:%10lu\n\
w_requests: %10lu\n\
writes: %10lu\n\
r_requests: %10lu\n\
reads: %10lu\n",
(ulong) pagecache_stats.blocks_used,
(ulong) pagecache_stats.global_blocks_changed,
(ulong) pagecache_stats.global_cache_w_requests,
(ulong) pagecache_stats.global_cache_write,
(ulong) pagecache_stats.global_cache_r_requests,
(ulong) pagecache_stats.global_cache_read);
}
maria_end();
my_free(blob_buffer);
my_uuid_end();
my_end(silent ? MY_CHECK_ERROR : MY_CHECK_ERROR | MY_GIVE_INFO); return(0);
err:
printf("got error: %d when using MARIA-database\n",my_errno);
err2: if (file)
{ if (maria_commit(file))
printf("got error: %d when using MARIA-database\n",my_errno);
maria_close(file);
}
maria_end();
my_uuid_end();
my_end(0); return(1);
} /* main */
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.31Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.