Commit 5cbf4e38 authored by vasil's avatar vasil

branches/zip:

Implement a limit on the memory used by the INNODB_TRX, INNODB_LOCKS and
INNODB_LOCK_WAITS tables. The maximum allowed memory is defined with the
macro TRX_I_S_MEM_LIMIT.

Approved by:	Marko (via IM)
parent 7be8ffc2
......@@ -60,14 +60,19 @@ ha_storage_get(
Copies data into the storage and returns a pointer to the copy. If the
same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. */
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
data_len bytes need to be allocated) and the size of storage is going to
become more than "memlim" then "data" is not added and NULL is returned.
To disable this behavior "memlim" can be set to 0, which stands for
"no limit". */
const void*
ha_storage_put(
/*===========*/
ha_storage_put_memlim(
/*==================*/
ha_storage_t* storage, /* in/out: hash storage */
const void* data, /* in: data to store */
ulint data_len) /* in: data length */
ulint data_len, /* in: data length */
ulint memlim) /* in: memory limit to obey */
{
void* raw;
ha_storage_node_t* node;
......@@ -81,7 +86,14 @@ ha_storage_put(
return(data_copy);
}
/* not present, add it */
/* not present */
/* check if we are allowed to allocate data_len bytes */
if (memlim > 0
&& ha_storage_get_size(storage) + data_len > memlim) {
return(NULL);
}
/* we put the auxiliary node struct and the data itself in one
continuous block */
......@@ -111,3 +123,44 @@ ha_storage_put(
hash table */
return(data_copy);
}
#ifdef UNIV_COMPILE_TEST_FUNCS
void
test_ha_storage()
{
ha_storage_t* storage;
char buf[1024];
int i;
const void* stored[256];
const void* p;
storage = ha_storage_create(0, 0);
for (i = 0; i < 256; i++) {
memset(buf, i, sizeof(buf));
stored[i] = ha_storage_put(storage, buf, sizeof(buf));
}
//ha_storage_empty(&storage);
for (i = 255; i >= 0; i--) {
memset(buf, i, sizeof(buf));
p = ha_storage_put(storage, buf, sizeof(buf));
if (p != stored[i]) {
fprintf(stderr, "ha_storage_put() returned %p "
"instead of %p, i=%d\n", p, stored[i], i);
return;
}
}
fprintf(stderr, "all ok\n");
ha_storage_free(storage);
}
#endif /* UNIV_COMPILE_TEST_FUNCS */
......@@ -833,14 +833,22 @@ trx_i_s_common_fill_table(
referenced */
cache = trx_i_s_cache;
/* which table we have to fill? */
table_name = tables->schema_table_name;
/* or table_name = tables->schema_table->table_name; */
/* update the cache */
trx_i_s_cache_start_write(cache);
trx_i_s_possibly_fetch_data_into_cache(cache);
trx_i_s_cache_end_write(cache);
/* which table we have to fill? */
table_name = tables->schema_table_name;
/* or table_name = tables->schema_table->table_name; */
if (trx_i_s_cache_is_truncated(cache)) {
/* XXX show warning to user if possible */
fprintf(stderr, "Warning: data in %s truncated due to "
"memory limit of %d bytes\n", table_name,
TRX_I_S_MEM_LIMIT);
}
ret = 0;
......
......@@ -35,6 +35,31 @@ ha_storage_create(
ulint initial_hash_cells); /* in: initial number of cells
in the hash table */
/***********************************************************************
Copies data into the storage and returns a pointer to the copy. If the
same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. If "data" is not present (and thus
data_len bytes need to be allocated) and the size of storage is going to
become more than "memlim" then "data" is not added and NULL is returned.
To disable this behavior "memlim" can be set to 0, which stands for
"no limit". */
const void*
ha_storage_put_memlim(
/*==================*/
/* out: pointer to the copy */
ha_storage_t* storage, /* in/out: hash storage */
const void* data, /* in: data to store */
ulint data_len, /* in: data length */
ulint memlim); /* in: memory limit to obey */
/***********************************************************************
Same as ha_storage_put_memlim() but without memory limit. */
#define ha_storage_put(storage, data, data_len) \
ha_storage_put_memlim((storage), (data), (data_len), 0)
/***********************************************************************
Copies string into the storage and returns a pointer to the copy. If the
same string is already present, then pointer to it is returned.
......@@ -44,17 +69,12 @@ Strings are considered to be equal if strcmp(str1, str2) == 0. */
((const char*) ha_storage_put((storage), (str), strlen(str) + 1))
/***********************************************************************
Copies data into the storage and returns a pointer to the copy. If the
same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. */
Copies string into the storage and returns a pointer to the copy obeying
a memory limit. */
const void*
ha_storage_put(
/*===========*/
ha_storage_t* storage, /* in/out: hash storage */
const void* data, /* in: data to store */
ulint data_len); /* in: data length */
#define ha_storage_put_str_memlim(storage, str, memlim) \
((const char*) ha_storage_put_memlim((storage), (str), \
strlen(str) + 1, (memlim)))
/***********************************************************************
Empties a hash storage, freeing memory occupied by data chunks.
......
......@@ -14,6 +14,10 @@ Created July 17, 2007 Vasil Dimov
#include "univ.i"
#include "ut0ut.h"
/* the maximum amount of memory that can be consumed by innodb_trx,
innodb_locks and innodb_lock_waits information schema tables. */
#define TRX_I_S_MEM_LIMIT 16777216 /* 16 MiB */
/* the maximum length of a string that can be stored in
i_s_locks_row_t::lock_data */
#define TRX_I_S_LOCK_DATA_MAX_LEN 8192
......@@ -157,6 +161,16 @@ trx_i_s_possibly_fetch_data_into_cache(
/* out: 0 - fetched, 1 - not */
trx_i_s_cache_t* cache); /* in/out: cache */
/***********************************************************************
Returns TRUE if the data in the cache is truncated due to the memory
limit posed by TRX_I_S_MEM_LIMIT. */
ibool
trx_i_s_cache_is_truncated(
/*=======================*/
/* out: TRUE if truncated */
trx_i_s_cache_t* cache); /* in: cache */
/* The maximum length that may be required by lock_id_size in
trx_i_s_create_lock_id(). "%llu:%lu:%lu:%lu" -> 84 chars */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment