Blob Blame History Raw
From aea4494eeb5351bcc26bf5e15411c28b96648445 Mon Sep 17 00:00:00 2001
From: Thierry Bordaz <tbordaz@redhat.com>
Date: Fri, 1 Feb 2019 15:36:01 +0100
Subject: [PATCH] Ticket 50177 - import task should not be deleted too rapidely
 after import finishes to be able to query the status

Bug Description:
	scripts that create online import and export tasks do not define a Time To Life of the tasks.
	As a consequence the task entry is cleared 2min (default value) after task completion.
	This is too rapid and some admin scripts may miss the final task status.

Fix Description:
	The fix is to keep the entry of completed online import and export tasks for 1 day.
	It also allows defines a default TTL to 1h (instead of 2min)

https://pagure.io/389-ds-base/issue/50177

Reviewed by: Mark Reynolds

Platforms tested: F27

Flag Day: no

Doc impact: no
---
 ldap/admin/src/scripts/db2ldif.pl.in | 3 ++-
 ldap/admin/src/scripts/ldif2db.pl.in | 3 ++-
 ldap/servers/slapd/task.c            | 6 +++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/ldap/admin/src/scripts/db2ldif.pl.in b/ldap/admin/src/scripts/db2ldif.pl.in
index 0d220f00a..f7d12b48a 100644
--- a/ldap/admin/src/scripts/db2ldif.pl.in
+++ b/ldap/admin/src/scripts/db2ldif.pl.in
@@ -241,7 +241,8 @@ if ($decrypt_on_export != 0) { $nsexportdecrypt = "nsExportDecrypt: true\n"; }
 $nsprintkey = "";
 if ($printkey == 0) { $nsprintkey = "nsPrintKey: false\n"; }
 $nsldiffile = "nsFilename: ${ldiffile}\n";
-$entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsreplica}${nsnobase64}${nsnowrap}${nsnoversion}${nsnouniqueid}${nsuseid2entry}${nsonefile}${nsexportdecrypt}${nsprintkey}${nsldiffile}";
+$ttl = "ttl: 86400";
+$entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsreplica}${nsnobase64}${nsnowrap}${nsnoversion}${nsnouniqueid}${nsuseid2entry}${nsonefile}${nsexportdecrypt}${nsprintkey}${nsldiffile}${ttl}";
 
 print("Exporting to ldif file: ${ldiffile}\n");
 $rc = DSUtil::ldapmod($entry, %info);
diff --git a/ldap/admin/src/scripts/ldif2db.pl.in b/ldap/admin/src/scripts/ldif2db.pl.in
index a5d834f8e..486dcd053 100644
--- a/ldap/admin/src/scripts/ldif2db.pl.in
+++ b/ldap/admin/src/scripts/ldif2db.pl.in
@@ -192,7 +192,8 @@ $nsmergechunksiz = "nsImportChunkSize: ${mergechunksiz}\n";
 $nsgenuniqid = "nsUniqueIdGenerator: ${genuniqid}\n"; 
 $nsuniqidname = "";
 if ($uniqidname ne "") { $nsuniqidname = "nsUniqueIdGeneratorNamespace: ${uniqidname}\n"; }
-$entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsldiffiles}${nsnoattrindexes}${nsimportencrypt}${nsmergechunksiz}${nsgenuniqid}${nsuniqidname}";
+$ttl = "ttl: 86400";
+$entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsldiffiles}${nsnoattrindexes}${nsimportencrypt}${nsmergechunksiz}${nsgenuniqid}${nsuniqidname}${ttl}";
 
 $rc = DSUtil::ldapmod($entry, %info);
 
diff --git a/ldap/servers/slapd/task.c b/ldap/servers/slapd/task.c
index 698ee19b9..8c48c05b8 100644
--- a/ldap/servers/slapd/task.c
+++ b/ldap/servers/slapd/task.c
@@ -46,7 +46,7 @@ static int shutting_down = 0;
 #define TASK_PROGRESS_NAME "nsTaskCurrentItem"
 #define TASK_WORK_NAME "nsTaskTotalItems"
 
-#define DEFAULT_TTL "120"                        /* seconds */
+#define DEFAULT_TTL "3600"                        /* seconds */
 #define TASK_SYSCONFIG_FILE_ATTR "sysconfigfile" /* sysconfig reload task file attr */
 #define TASK_SYSCONFIG_LOGCHANGES_ATTR "logchanges"
 #define TASK_TOMBSTONE_FIXUP "fixup tombstones task"
@@ -387,8 +387,8 @@ slapi_task_status_changed(Slapi_Task *task)
         if (e == NULL)
             return;
         ttl = atoi(fetch_attr(e, "ttl", DEFAULT_TTL));
-        if (ttl > 3600)
-            ttl = 3600; /* be reasonable. */
+        if (ttl > (24*3600))
+            ttl = (24*3600); /* be reasonable, allow to check task status not longer than one day  */
         expire = time(NULL) + ttl;
         task->task_flags |= SLAPI_TASK_DESTROYING;
         /* queue an event to destroy the state info */
-- 
2.17.2