summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bell@desktop.sanja.is.com.ua>2008-01-09 21:56:05 +0200
committerunknown <bell@desktop.sanja.is.com.ua>2008-01-09 21:56:05 +0200
commit9b9175ff752957d32a3c532fed0ed52123efa234 (patch)
tree7614ec837bec038e9975d90102e6c18f940f943b
parentfb8a065e8ad8b6591d727f658d43a084f872ece6 (diff)
parent62d9e3eb1bbbcf659c3c6b4e8601a8f2e0f29b15 (diff)
downloadmariadb-git-9b9175ff752957d32a3c532fed0ed52123efa234.tar.gz
Merge desktop.sanja.is.com.ua:/home/bell/mysql/bk/mysql-maria
into desktop.sanja.is.com.ua:/home/bell/mysql/bk/work-maria-pin storage/maria/ma_pagecache.c: Auto merged
-rw-r--r--storage/maria/ma_pagecache.c4
-rw-r--r--storage/maria/unittest/ma_pagecache_single.c130
2 files changed, 123 insertions, 11 deletions
diff --git a/storage/maria/ma_pagecache.c b/storage/maria/ma_pagecache.c
index 4b0dada3a6b..b68bcebd63f 100644
--- a/storage/maria/ma_pagecache.c
+++ b/storage/maria/ma_pagecache.c
@@ -2373,6 +2373,10 @@ static my_bool make_lock_and_pin(PAGECACHE *pagecache,
info_add_lock(block, 0);
break;
case PAGECACHE_LOCK_LEFT_UNLOCKED: /* free -> free */
+ if (pin == PAGECACHE_UNPIN)
+ {
+ remove_pin(block);
+ }
case PAGECACHE_LOCK_LEFT_WRITELOCKED: /* write -> write */
break; /* do nothing */
default:
diff --git a/storage/maria/unittest/ma_pagecache_single.c b/storage/maria/unittest/ma_pagecache_single.c
index 1135051d8f2..16d608ec808 100644
--- a/storage/maria/unittest/ma_pagecache_single.c
+++ b/storage/maria/unittest/ma_pagecache_single.c
@@ -29,35 +29,50 @@ static PAGECACHE pagecache;
static struct file_desc simple_read_write_test_file[]=
{
{PAGE_SIZE, '\1'},
- { 0, 0}
+ {0, 0}
};
static struct file_desc simple_read_change_write_read_test_file[]=
{
{PAGE_SIZE/2, '\65'},
{PAGE_SIZE/2, '\1'},
- { 0, 0}
+ {0, 0}
};
static struct file_desc simple_pin_test_file1[]=
{
{PAGE_SIZE*2, '\1'},
- { 0, 0}
+ {0, 0}
};
static struct file_desc simple_pin_test_file2[]=
{
{PAGE_SIZE/2, '\1'},
{PAGE_SIZE/2, (unsigned char)129},
{PAGE_SIZE, '\1'},
- { 0, 0}
+ {0, 0}
};
-static struct file_desc simple_delete_forget_test_file[]=
+static struct file_desc simple_pin_no_lock_test_file1[]=
+{
+ {PAGE_SIZE, '\4'},
+ {0, 0}
+};
+static struct file_desc simple_pin_no_lock_test_file2[]=
+{
+ {PAGE_SIZE, '\5'},
+ {0, 0}
+};
+static struct file_desc simple_pin_no_lock_test_file3[]=
+{
+ {PAGE_SIZE, '\6'},
+ {0, 0}
+};
+static struct file_desc simple_delete_forget_test_file[]=
{
{PAGE_SIZE, '\1'},
- { 0, 0}
+ {0, 0}
};
-static struct file_desc simple_delete_flush_test_file[]=
+static struct file_desc simple_delete_flush_test_file[]=
{
{PAGE_SIZE, '\2'},
- { 0, 0}
+ {0, 0}
};
@@ -220,7 +235,6 @@ int simple_read_change_write_read_test()
int simple_pin_test()
{
unsigned char *buffw= malloc(PAGE_SIZE);
- unsigned char *buffr= malloc(PAGE_SIZE);
int res;
DBUG_ENTER("simple_pin_test");
/* prepare the file */
@@ -286,11 +300,104 @@ int simple_pin_test()
reset_file(&file1, file1_name);
err:
free(buffw);
- free(buffr);
DBUG_RETURN(res);
}
/*
+ Checks pins without lock.
+*/
+int simple_pin_no_lock_test()
+{
+ unsigned char *buffw= malloc(PAGE_SIZE);
+ PAGECACHE_BLOCK_LINK *link;
+ int res;
+ DBUG_ENTER("simple_pin_no_lock_test");
+ /* prepare the file */
+ bfill(buffw, PAGE_SIZE, '\4');
+ pagecache_write(&pagecache, &file1, 0, 3, (char*)buffw,
+ PAGECACHE_PLAIN_PAGE,
+ PAGECACHE_LOCK_LEFT_UNLOCKED,
+ PAGECACHE_PIN_LEFT_UNPINNED,
+ PAGECACHE_WRITE_DELAY,
+ 0, LSN_IMPOSSIBLE);
+ /* test */
+ if (flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
+ {
+ diag("Got error during flushing pagecache 2\n");
+ exit(1);
+ }
+ bfill(buffw, PAGE_SIZE, '\5');
+ pagecache_write(&pagecache, &file1, 0, 3, (char*)buffw,
+ PAGECACHE_PLAIN_PAGE,
+ PAGECACHE_LOCK_LEFT_UNLOCKED,
+ PAGECACHE_PIN,
+ PAGECACHE_WRITE_DELAY,
+ 0, LSN_IMPOSSIBLE);
+ /*
+ We have to get error because one page of the file is pinned,
+ other page should be flushed
+ */
+ if (!flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
+ {
+ diag("Did not get error in flush_pagecache_blocks 2\n");
+ res= 0;
+ goto err;
+ }
+ ok((res= test(test_file(file1, file1_name, PAGE_SIZE, PAGE_SIZE,
+ simple_pin_no_lock_test_file1))),
+ "Simple pin (no lock) page file with pin 2");
+ pagecache_unlock(&pagecache,
+ &file1,
+ 0,
+ PAGECACHE_LOCK_LEFT_UNLOCKED,
+ PAGECACHE_UNPIN,
+ 0, 0, 0);
+ if (flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
+ {
+ diag("Got error in flush_pagecache_blocks 2\n");
+ res= 0;
+ goto err;
+ }
+ ok((res&= test(test_file(file1, file1_name, PAGE_SIZE, PAGE_SIZE,
+ simple_pin_no_lock_test_file2))),
+ "Simple pin (no lock) page result file 2");
+
+ bfill(buffw, PAGE_SIZE, '\6');
+ pagecache_write(&pagecache, &file1, 0, 3, (char*)buffw,
+ PAGECACHE_PLAIN_PAGE,
+ PAGECACHE_LOCK_WRITE,
+ PAGECACHE_PIN,
+ PAGECACHE_WRITE_DELAY,
+ &link, LSN_IMPOSSIBLE);
+ pagecache_unlock_by_link(&pagecache, link,
+ PAGECACHE_LOCK_WRITE_UNLOCK,
+ PAGECACHE_PIN_LEFT_PINNED, 0, 0, 1);
+ if (!flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
+ {
+ diag("Did not get error in flush_pagecache_blocks 3\n");
+ res= 0;
+ goto err;
+ }
+ ok((res= test(test_file(file1, file1_name, PAGE_SIZE, PAGE_SIZE,
+ simple_pin_no_lock_test_file2))),
+ "Simple pin (no lock) page file with pin 3");
+ pagecache_unpin_by_link(&pagecache, link, 0);
+ if (flush_pagecache_blocks(&pagecache, &file1, FLUSH_FORCE_WRITE))
+ {
+ diag("Got error in flush_pagecache_blocks 3\n");
+ res= 0;
+ goto err;
+ }
+ ok((res&= test(test_file(file1, file1_name, PAGE_SIZE, PAGE_SIZE,
+ simple_pin_no_lock_test_file3))),
+ "Simple pin (no lock) page result file 3");
+ if (res)
+ reset_file(&file1, file1_name);
+err:
+ free(buffw);
+ DBUG_RETURN(res);
+}
+/*
Prepare page, write new value, then delete page from cache without flush,
on the disk should be page with old content written during preparation
*/
@@ -476,6 +583,7 @@ static void *test_thread(void *arg)
if (!simple_read_write_test() ||
!simple_read_change_write_read_test() ||
!simple_pin_test() ||
+ !simple_pin_no_lock_test() ||
!simple_delete_forget_test() ||
!simple_delete_flush_test())
exit(1);
@@ -572,7 +680,7 @@ int main(int argc __attribute__((unused)),
VOID(thr_setconcurrency(2));
#endif
- plan(12);
+ plan(16);
if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
PAGE_SIZE, MYF(MY_WME))) == 0)