[tracker] Check space before creating DBs && disable indexer API when paused
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Check space before creating DBs && disable indexer API when paused
- Date: Mon, 22 Jun 2009 09:51:10 -0400 (EDT)
commit 11f544034d89f139250f6fcfad1a310a47facf0d
Author: Martyn Russell <martyn imendio com>
Date: Mon Jun 1 11:43:32 2009 +0100
Check space before creating DBs && disable indexer API when paused
The debugging is also a bit clearer when we are below the disk space
threshold as set in the config. The frequency of these messages is
slightly longer too so we don't fill the logs up so quickly.
Ported to master by Philip
src/libtracker-common/tracker-file-utils.c | 40 ++++++++++++++++++++++++++++
src/libtracker-common/tracker-file-utils.h | 3 ++
src/libtracker-db/tracker-db-manager.c | 14 +++++++--
src/libtracker-db/tracker-db-manager.h | 2 +-
src/tracker-utils/tracker-processes.c | 5 +++-
src/trackerd/tracker-backup.c | 27 ++++++++++++++----
src/trackerd/tracker-main.c | 5 +++-
src/trackerd/tracker-processor.c | 2 +-
src/trackerd/tracker-status.c | 4 ++-
9 files changed, 88 insertions(+), 14 deletions(-)
---
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index fa8b202..bcd179c 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <fcntl.h>
#include <limits.h>
@@ -178,6 +179,45 @@ tracker_file_get_mime_type (GFile *file)
return content_type ? content_type : g_strdup ("unknown");
}
+gboolean
+tracker_file_system_has_enough_space (const gchar *path,
+ gulong required_bytes)
+{
+ struct statvfs st;
+ gchar *str1;
+ gchar *str2;
+ gboolean enough;
+
+ g_return_val_if_fail (path != NULL, FALSE);
+
+ if (statvfs (path, &st) == -1) {
+ g_critical ("Could not statvfs() '%s'", path);
+ return FALSE;
+ }
+
+ str1 = g_format_size_for_display (required_bytes);
+ str2 = g_format_size_for_display (st.f_bsize * st.f_bavail);
+
+ enough = ((long long) st.f_bsize * st.f_bavail) <= required_bytes;
+
+ if (!enough) {
+ g_critical ("Not enough disk space to create databases, "
+ "%s remaining, %s required as a minimum",
+ str2,
+ str1);
+ } else {
+ g_message ("Checking for adequate disk space to create databases, "
+ "%s remaining, %s required as a minimum",
+ str2,
+ str1);
+ }
+
+ g_free (str2);
+ g_free (str1);
+
+ return enough;
+}
+
void
tracker_path_remove (const gchar *path)
{
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index 8edcc02..8c9c956 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -38,6 +38,8 @@ void tracker_file_close (FILE *file,
goffset tracker_file_get_size (const gchar *uri);
guint64 tracker_file_get_mtime (const gchar *uri);
gchar * tracker_file_get_mime_type (GFile *file);
+gboolean tracker_file_system_has_enough_space (const gchar *path,
+ gulong required_bytes);
void tracker_path_remove (const gchar *uri);
gboolean tracker_path_is_in_path (const gchar *path,
const gchar *in_path);
@@ -45,6 +47,7 @@ void tracker_path_hash_table_filter_duplicates (GHashTable *roots);
GSList * tracker_path_list_filter_duplicates (GSList *roots,
const gchar *basename_exception_prefix);
gchar * tracker_path_evaluate_name (const gchar *uri);
+
gboolean tracker_env_check_xdg_dirs (void);
#endif /* __LIBTRACKER_COMMON_FILE_UTILS_H__ */
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 64589ab..4b5ead0 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -42,6 +42,9 @@
/* ZLib buffer settings */
#define ZLIB_BUF_SIZE 8192
+/* Required minimum space needed to create databases (5Mb) */
+#define TRACKER_DB_MIN_REQUIRED_SPACE 5242880
+
/* Default memory settings for databases */
#define TRACKER_DB_PAGE_SIZE_DONT_SET -1
@@ -1018,7 +1021,7 @@ tracker_db_manager_ensure_locale (void)
g_free (stored_locale);
}
-void
+gboolean
tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time,
gboolean shared_cache)
@@ -1035,7 +1038,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
}
if (initialized) {
- return;
+ return TRUE;
}
need_reindex = FALSE;
@@ -1136,7 +1139,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
*/
if ((flags & TRACKER_DB_MANAGER_REMOVE_ALL) != 0) {
initialized = TRUE;
- return;
+ return TRUE;
}
/* Set general database options */
@@ -1154,6 +1157,10 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
*first_time = TRUE;
}
+ if (!tracker_file_system_has_enough_space (data_dir, TRACKER_DB_MIN_REQUIRED_SPACE)) {
+ return FALSE;
+ }
+
/* We call an internal version of this function here
* because at the time 'initialized' = FALSE and that
* will cause errors and do nothing.
@@ -1207,6 +1214,7 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
TRACKER_DB_FULLTEXT,
TRACKER_DB_CONTENTS,
TRACKER_DB_COMMON);
+ return TRUE;
}
void
diff --git a/src/libtracker-db/tracker-db-manager.h b/src/libtracker-db/tracker-db-manager.h
index b7023a7..7464f7a 100644
--- a/src/libtracker-db/tracker-db-manager.h
+++ b/src/libtracker-db/tracker-db-manager.h
@@ -53,7 +53,7 @@ typedef enum {
GType tracker_db_get_type (void) G_GNUC_CONST;
-void tracker_db_manager_init (TrackerDBManagerFlags flags,
+gboolean tracker_db_manager_init (TrackerDBManagerFlags flags,
gboolean *first_time,
gboolean shared_cache);
void tracker_db_manager_shutdown (void);
diff --git a/src/tracker-utils/tracker-processes.c b/src/tracker-utils/tracker-processes.c
index e61a8ae..344853d 100644
--- a/src/tracker-utils/tracker-processes.c
+++ b/src/tracker-utils/tracker-processes.c
@@ -246,7 +246,10 @@ main (int argc, char **argv)
g_log_set_default_handler (log_handler, NULL);
/* Clean up */
- tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE);
+ if (!tracker_db_manager_init (TRACKER_DB_MANAGER_REMOVE_ALL, NULL, FALSE)) {
+ return EXIT_FAILURE;
+ }
+
tracker_db_manager_remove_all ();
tracker_db_manager_shutdown ();
diff --git a/src/trackerd/tracker-backup.c b/src/trackerd/tracker-backup.c
index aae97b0..65d4bb2 100644
--- a/src/trackerd/tracker-backup.c
+++ b/src/trackerd/tracker-backup.c
@@ -22,13 +22,14 @@
#include <glib-object.h>
#include <glib/gstdio.h>
+
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-data/tracker-data-backup.h>
#include "tracker-dbus.h"
#include "tracker-indexer-client.h"
#include "tracker-backup.h"
-
+#include "tracker-status.h"
G_DEFINE_TYPE (TrackerBackup, tracker_backup, G_TYPE_OBJECT)
@@ -93,7 +94,8 @@ tracker_backup_restore (TrackerBackup *object,
GError **error)
{
guint request_id;
- GError *err = NULL;
+ GError *actual_error = NULL;
+ GError *restore_error = NULL;
request_id = tracker_dbus_get_next_request_id ();
@@ -101,20 +103,33 @@ tracker_backup_restore (TrackerBackup *object,
"DBus request to restore backup from '%s'",
path);
+ /* First check we have disk space, we do this with ALL our
+ * indexer commands.
+ */
+ if (tracker_status_get_is_paused_for_space ()) {
+ tracker_dbus_request_failed (request_id,
+ &actual_error,
+ "No disk space left to write to the databases");
+ dbus_g_method_return_error (context, actual_error);
+ g_error_free (actual_error);
+ return;
+ }
+
org_freedesktop_Tracker_Indexer_restore_backup (tracker_dbus_indexer_get_proxy (),
- path, &err);
+ path,
+ &restore_error);
- if (err) {
+ if (restore_error) {
GError *actual_error = NULL;
tracker_dbus_request_failed (request_id,
&actual_error,
- err->message);
+ restore_error->message);
dbus_g_method_return_error (context, actual_error);
g_error_free (actual_error);
- g_error_free (err);
+ g_error_free (restore_error);
} else {
dbus_g_method_return (context);
tracker_dbus_request_success (request_id);
diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index b6de421..18b257d 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -761,6 +761,7 @@ backup_user_metadata (TrackerConfig *config, TrackerLanguage *language)
/*
* Init the DB stack to get the user metadata
*/
+
tracker_data_manager_init (config, language, 0, NULL, &is_first_time_index);
/*
@@ -1080,7 +1081,9 @@ main (gint argc, gchar *argv[])
flags |= TRACKER_DB_MANAGER_LOW_MEMORY_MODE;
}
- tracker_data_manager_init (config, language, flags, NULL, &is_first_time_index);
+ if (!tracker_data_manager_init (config, language, flags, NULL, &is_first_time_index)) {
+ return EXIT_FAILURE;
+ }
tracker_status_set_is_first_time_index (is_first_time_index);
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index d02bafc..7cfc8dd 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -635,7 +635,7 @@ item_queue_handlers_cb (gpointer user_data)
/* Don't spam */
g_get_current_time (&time_now);
- should_repeat = (time_now.tv_sec - time_last.tv_sec) >= 5;
+ should_repeat = (time_now.tv_sec - time_last.tv_sec) >= 10;
if (should_repeat) {
time_last = time_now;
}
diff --git a/src/trackerd/tracker-status.c b/src/trackerd/tracker-status.c
index f5eea84..bc4f3fb 100644
--- a/src/trackerd/tracker-status.c
+++ b/src/trackerd/tracker-status.c
@@ -305,7 +305,9 @@ disk_space_check (void)
}
if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
- g_message ("Disk space is low");
+ g_message ("WARNING: Available disk space is below configured "
+ "threshold for acceptable working (%d%%)",
+ limit);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]