summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/ha_berkeley.cc4
-rw-r--r--sql/ha_federated.cc4
-rw-r--r--sql/ha_heap.cc4
-rw-r--r--sql/ha_innodb.cc4
-rw-r--r--sql/ha_myisam.cc4
-rw-r--r--sql/ha_myisammrg.cc4
-rw-r--r--sql/ha_ndbcluster.cc4
-rw-r--r--sql/ha_partition.cc4
-rw-r--r--sql/handler.cc189
-rw-r--r--sql/handler.h83
-rw-r--r--sql/log.cc4
-rw-r--r--storage/archive/ha_archive.cc5
-rw-r--r--storage/blackhole/ha_blackhole.cc4
-rw-r--r--storage/csv/ha_tina.cc7
-rw-r--r--storage/example/ha_example.cc8
15 files changed, 311 insertions, 21 deletions
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index 473fb149871..afa3d69da45 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -164,7 +164,9 @@ handlerton berkeley_hton = {
HTON_CLOSE_CURSORS_AT_COMMIT | HTON_FLUSH_AFTER_RENAME,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
handler *berkeley_create_handler(TABLE_SHARE *table)
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index f4fc5f47193..b1792ebe370 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -408,7 +408,9 @@ handlerton federated_hton= {
HTON_ALTER_NOT_SUPPORTED,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc
index 1a7efb42748..10d0c9eb267 100644
--- a/sql/ha_heap.cc
+++ b/sql/ha_heap.cc
@@ -65,7 +65,9 @@ handlerton heap_hton= {
HTON_CAN_RECREATE,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
static handler *heap_create_handler(TABLE_SHARE *table)
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 0b2f561e8c9..86d98953fa9 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -244,7 +244,9 @@ handlerton innobase_hton = {
HTON_NO_FLAGS,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- innobase_release_temporary_latches
+ innobase_release_temporary_latches,
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 40081c975c8..9114d0ceda8 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -99,7 +99,9 @@ handlerton myisam_hton= {
HTON_CAN_RECREATE,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index f4a052cea8a..0ab5222d110 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -77,7 +77,9 @@ handlerton myisammrg_hton= {
HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
static handler *myisammrg_create_handler(TABLE_SHARE *table)
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index f46a5eccabf..28a3c22aa0d 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -81,7 +81,9 @@ handlerton ndbcluster_hton = {
ndbcluster_init,
~(uint)0, /* slot */
/* below are initialized by name in ndbcluster_init() */
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
static handler *ndbcluster_create_handler(TABLE_SHARE *table)
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 7b9dd00ed56..1a036e7fa6f 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -111,7 +111,9 @@ handlerton partition_hton = {
HTON_NOT_USER_SELECTABLE | HTON_HIDDEN,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
/*
diff --git a/sql/handler.cc b/sql/handler.cc
index b9ef05a33c2..dc8f66c9b14 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -75,7 +75,9 @@ const handlerton default_hton =
HTON_NO_FLAGS, /* flags */
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES;
@@ -2318,11 +2320,11 @@ void handler::get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id
****************************************************************************/
/*
- Initiates table-file and calls apropriate database-creator
+ Initiates table-file and calls appropriate database-creator
NOTES
We must have a write lock on LOCK_open to be sure no other thread
- interfers with table
+ interferes with table
RETURN
0 ok
@@ -2566,7 +2568,7 @@ int ha_discover(THD *thd, const char *db, const char *name,
/*
- Call this function in order to give the handler the possiblity
+ Call this function in order to give the handler the possibility
to ask engine if there are any new tables that should be written to disk
or any dropped tables that need to be removed from disk
*/
@@ -3331,3 +3333,182 @@ int handler::ha_delete_row(const byte *buf)
#endif
return 0;
}
+
+/*
+ Dummy function which accept information about log files which is not need
+ by handlers
+*/
+void signal_log_not_needed(struct handlerton, char *log_file)
+{
+ DBUG_ENTER("signal_log_not_needed");
+ DBUG_PRINT("enter", ("logfile '%s'", log_file));
+ DBUG_VOID_RETURN;
+}
+
+#ifdef TRANS_LOG_MGM_EXAMPLE_CODE
+/*
+ Example of transaction log management functions based on assumption that logs
+ placed into a directory
+*/
+#include <my_dir.h>
+#include <my_sys.h>
+int example_of_iterator_using_for_logs_cleanup(handlerton *hton)
+{
+ void *buffer;
+ int res= 1;
+ struct handler_iterator iterator;
+ struct handler_log_file_data data;
+
+ if (!hton->create_iterator)
+ return 1; /* iterator creator is not supported */
+
+ if ((*hton->create_iterator)(HA_TRANSACTLOG_ITERATOR, &iterator) !=
+ HA_ITERATOR_OK)
+ {
+ /* error during creation of log iterator or iterator is not supported */
+ return 1;
+ }
+ while((*iterator.next)(&iterator, (void*)&data) == 0)
+ {
+ printf("%s\n", data.filename.str);
+ if (data.status == HA_LOG_STATUS_FREE &&
+ my_delete(data.filename.str, MYF(MY_WME)))
+ goto err;
+ }
+ res= 0;
+err:
+ (*iterator.destroy)(&iterator);
+ return res;
+}
+
+
+/*
+ Here we should get info from handler where it save logs but here is
+ just example, so we use constant.
+ IMHO FN_ROOTDIR ("/") is safe enough for example, because nobody has
+ rights on it except root and it consist of directories only at lest for
+ *nix (sorry, can't find windows-safe solution here, but it is only example).
+*/
+#define fl_dir FN_ROOTDIR
+
+
+/*
+ Dummy function to return log status should be replaced by function which
+ really detect the log status and check that the file is a log of this
+ handler.
+*/
+enum log_status fl_get_log_status(char *log)
+{
+ MY_STAT stat_buff;
+ if (my_stat(log, &stat_buff, MYF(0)))
+ return HA_LOG_STATUS_INUSE;
+ return HA_LOG_STATUS_NOSUCHLOG;
+}
+
+
+struct fl_buff
+{
+ LEX_STRING *names;
+ enum log_status *statuses;
+ uint32 entries;
+ uint32 current;
+};
+
+
+int fl_log_iterator_next(struct handler_iterator *iterator,
+ void *iterator_object)
+{
+ struct fl_buff *buff= (struct fl_buff *)iterator->buffer;
+ struct handler_log_file_data *data=
+ (struct handler_log_file_data *) iterator_object;
+ if (buff->current >= buff->entries)
+ return 1;
+ data->filename= buff->names[buff->current];
+ data->status= buff->statuses[buff->current];
+ buff->current++;
+ return 0;
+}
+
+
+void fl_log_iterator_destroy(struct handler_iterator *iterator)
+{
+ my_free((gptr)iterator->buffer, MYF(MY_ALLOW_ZERO_PTR));
+}
+
+
+/*
+ returns buffer, to be assigned in handler_iterator struct
+*/
+enum handler_create_iterator_result
+fl_log_iterator_buffer_init(struct handler_iterator *iterator)
+{
+ MY_DIR *dirp;
+ struct fl_buff *buff;
+ char *name_ptr;
+ byte *ptr;
+ FILEINFO *file;
+ uint32 i;
+
+ /* to be able to make my_free without crash in case of error */
+ iterator->buffer= 0;
+
+ if (!(dirp = my_dir(fl_dir, MYF(0))))
+ {
+ return HA_ITERATOR_ERROR;
+ }
+ if ((ptr= (byte*)my_malloc(ALIGN_SIZE(sizeof(fl_buff)) +
+ ((ALIGN_SIZE(sizeof(LEX_STRING)) +
+ sizeof(enum log_status) +
+ + FN_REFLEN) *
+ (uint) dirp->number_off_files),
+ MYF(0))) == 0)
+ {
+ return HA_ITERATOR_ERROR;
+ }
+ buff= (struct fl_buff *)ptr;
+ buff->entries= buff->current= 0;
+ ptr= ptr + (ALIGN_SIZE(sizeof(fl_buff)));
+ buff->names= (LEX_STRING*) (ptr);
+ ptr= ptr + ((ALIGN_SIZE(sizeof(LEX_STRING)) *
+ (uint) dirp->number_off_files));
+ buff->statuses= (enum log_status *)(ptr);
+ name_ptr= (char *)(ptr + (sizeof(enum log_status) *
+ (uint) dirp->number_off_files));
+ for (i=0 ; i < (uint) dirp->number_off_files ; i++)
+ {
+ enum log_status st;
+ file= dirp->dir_entry + i;
+ if ((file->name[0] == '.' &&
+ ((file->name[1] == '.' && file->name[2] == '\0') ||
+ file->name[1] == '\0')))
+ continue;
+ if ((st= fl_get_log_status(file->name)) == HA_LOG_STATUS_NOSUCHLOG)
+ continue;
+ name_ptr= strxnmov(buff->names[buff->entries].str= name_ptr,
+ FN_REFLEN, fl_dir, file->name, NullS);
+ buff->names[buff->entries].length= (name_ptr -
+ buff->names[buff->entries].str) - 1;
+ buff->statuses[buff->entries]= st;
+ buff->entries++;
+ }
+
+ iterator->buffer= buff;
+ iterator->next= &fl_log_iterator_next;
+ iterator->destroy= &fl_log_iterator_destroy;
+ return HA_ITERATOR_OK;
+}
+
+
+/* An example of a iterator creator */
+enum handler_create_iterator_result
+fl_create_iterator(enum handler_iterator_type type,
+ struct handler_iterator *iterator)
+{
+ switch(type){
+ case HA_TRANSACTLOG_ITERATOR:
+ return fl_log_iterator_buffer_init(iterator);
+ default:
+ return HA_ITERATOR_UNSUPPORTED;
+ }
+}
+#endif /*TRANS_LOG_MGM_EXAMPLE_CODE*/
diff --git a/sql/handler.h b/sql/handler.h
index afee6bb9f8d..4bc4f8b0c68 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -461,6 +461,72 @@ typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
const char *status, uint status_len);
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
+/* Transaction log maintains type definitions */
+enum log_status
+{
+ HA_LOG_STATUS_FREE= 0, /* log is free and can be deleted */
+ HA_LOG_STATUS_INUSE= 1, /* log can't be deleted because it is in use */
+ HA_LOG_STATUS_NOSUCHLOG= 2 /* no such log (can't be returned by
+ the log iterator status) */
+};
+/*
+ Function for signaling that the log file changed its state from
+ LOG_STATUS_INUSE to LOG_STATUS_FREE
+
+ Now it do nothing, will be implemented as part of new transaction
+ log management for engines.
+ TODO: implement the function.
+*/
+void signal_log_not_needed(struct handlerton, char *log_file);
+/*
+ Data of transaction log iterator.
+*/
+struct handler_log_file_data {
+ LEX_STRING filename;
+ enum log_status status;
+};
+
+
+enum handler_iterator_type
+{
+ /* request of transaction log iterator */
+ HA_TRANSACTLOG_ITERATOR= 1
+};
+enum handler_create_iterator_result
+{
+ HA_ITERATOR_OK, /* iterator created */
+ HA_ITERATOR_UNSUPPORTED, /* such type of iterator is not supported */
+ HA_ITERATOR_ERROR /* error during iterator creation */
+};
+
+/*
+ Iterator structure. Can be used by handler/handlerton for different purposes.
+
+ Iterator should be created in the way to point "before" the first object
+ it iterate, so next() call move it to the first object or return !=0 if
+ there is nothing to iterate through.
+*/
+struct handler_iterator {
+ /*
+ Moves iterator to next record and return 0 or return !=0
+ if there is no records.
+ iterator_object will be filled by this function if next() returns 0.
+ Content of the iterator_object depend on iterator type.
+ */
+ int (*next)(struct handler_iterator *, void *iterator_object);
+ /*
+ Free resources allocated by iterator, after this call iterator
+ is not usable.
+ */
+ void (*destroy)(struct handler_iterator *);
+ /*
+ Pointer to buffer for the iterator to use.
+ Should be allocated by function which created the iterator and
+ destroied by freed by above "destroy" call
+ */
+ void *buffer;
+};
+
/*
handlerton is a singleton structure - one instance per storage engine -
to provide access to storage engine functionality that works on the
@@ -585,6 +651,23 @@ struct handlerton
const char *query, uint query_length,
const char *db, const char *table_name);
int (*release_temporary_latches)(THD *thd);
+
+ /*
+ Get log status.
+ If log_status is null then the handler do not support transaction
+ log information (i.e. log iterator can't be created).
+ (see example of implementation in handler.cc, TRANS_LOG_MGM_EXAMPLE_CODE)
+
+ */
+ enum log_status (*get_log_status)(char *log);
+
+ /*
+ Iterators creator.
+ Presence of the pointer should be checked before using
+ */
+ enum handler_create_iterator_result
+ (*create_iterator)(enum handler_iterator_type type,
+ struct handler_iterator *fill_this_in);
};
extern const handlerton default_hton;
diff --git a/sql/log.cc b/sql/log.cc
index 31133a71757..e0e77a5f5a5 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -117,7 +117,9 @@ handlerton binlog_hton = {
HTON_NOT_USER_SELECTABLE | HTON_HIDDEN,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc
index e39ee976eb1..28f70ff7df8 100644
--- a/storage/archive/ha_archive.cc
+++ b/storage/archive/ha_archive.cc
@@ -185,8 +185,9 @@ handlerton archive_hton = {
HTON_NO_FLAGS,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
-
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
static handler *archive_create_handler(TABLE_SHARE *table)
diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc
index 098e44f39ee..a4594c81dd4 100644
--- a/storage/blackhole/ha_blackhole.cc
+++ b/storage/blackhole/ha_blackhole.cc
@@ -70,7 +70,9 @@ handlerton blackhole_hton= {
HTON_CAN_RECREATE | HTON_ALTER_CANNOT_CREATE,
NULL, /* binlog_func */
NULL, /* binlog_log_query */
- NULL /* release_temporary_latches */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc
index a26114e086d..b2f759765c2 100644
--- a/storage/csv/ha_tina.cc
+++ b/storage/csv/ha_tina.cc
@@ -113,8 +113,11 @@ handlerton tina_hton= {
NULL, /* Alter Tablespace */
NULL, /* Fill FILES Table */
HTON_CAN_RECREATE,
- NULL, /* binlog_func */
- NULL /* binlog_log_query */
+ NULL, /* binlog_func */
+ NULL, /* binlog_log_query */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
/*****************************************************************************
diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc
index 2ce543dfbb0..13fc5385b13 100644
--- a/storage/example/ha_example.cc
+++ b/storage/example/ha_example.cc
@@ -113,9 +113,11 @@ handlerton example_hton= {
NULL, /* Alter tablespace */
NULL, /* Fill Files table */
HTON_CAN_RECREATE,
- NULL,
- NULL,
- NULL,
+ NULL, /* binlog_func */
+ NULL, /* binlog_log_query */
+ NULL, /* release_temporary_latches */
+ NULL, /* get_log_status */
+ NULL /* create_iterator */
};
/* Variables for example share methods */