Browse Source

Ticket 49091 - remove usage of changelog semaphore

it was used to replace a serial lock, but now the writing to the changelog is done inside the txn and already serialized by the backend lock.
we can remove unnecessary code

Reviewed by: Thierry, William - thanks
Ludwig Krispenz 9 years ago
parent
commit
13b80015b2

+ 0 - 104
ldap/servers/plugins/replication/cl5_api.c

@@ -136,8 +136,6 @@ typedef struct cl5dbfile
 							 * or as initialized */
     RUV  *purgeRUV;         /* ruv to which the file has been purged */
     RUV  *maxRUV;           /* ruv that marks the upper boundary of the data */
-	char *semaName;			/* semaphore name */ 
-	PRSem *sema;			/* semaphore for max concurrent cl writes */
 }CL5DBFile;
 
 /* structure that allows to iterate through entries to be sent to a consumer
@@ -3347,7 +3345,6 @@ static int  _cl5Delete (const char *clDir, int rmDir)
 
 static void _cl5SetDefaultDBConfig(void)
 {
-  s_cl5Desc.dbConfig.maxConcurrentWrites= CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES;
   s_cl5Desc.dbConfig.fileMode           = FILE_CREATE_MODE;
 }
 
@@ -3355,7 +3352,6 @@ static void _cl5SetDBConfig (const CL5DBConfig *config)
 {
   /* s_cl5Desc.dbConfig.pageSize is retrieved from backend */
   /* Some other configuration parameters are hardcoded... */
-  s_cl5Desc.dbConfig.maxConcurrentWrites = config->maxConcurrentWrites;
   s_cl5Desc.dbConfig.fileMode = FILE_CREATE_MODE;
 }
 
@@ -5045,15 +5041,7 @@ static int _cl5WriteOperationTxn(const char *replName, const char *replGen,
 			goto done;
 		}
 
-		if ( file->sema )
-		{
-			PR_WaitSemaphore(file->sema);
-		}
 		rc = file->db->put(file->db, txnid, &key, data, 0);
-		if ( file->sema )
-		{
-			PR_PostSemaphore(file->sema);
-		}
 		if (CL5_OS_ERR_IS_DISKFULL(rc))
 		{
 			slapi_log_err(SLAPI_LOG_CRIT, repl_plugin_name_cl,
@@ -6084,7 +6072,6 @@ static int _cl5NewDBFile (const char *replName, const char *replGen, CL5DBFile**
 	int rc;
 	DB *db = NULL;
 	char *name;
-	char *semadir;
 #ifdef HPUX
 	char cwd [PATH_MAX+1];
 #endif
@@ -6149,91 +6136,6 @@ out:
     (*dbFile)->replName = slapi_ch_strdup (replName);
     (*dbFile)->replGen = slapi_ch_strdup (replGen);
 
-	/*
-	 * Considerations for setting up cl semaphore:
-	 * (1) The NT version of SleepyCat uses test-and-set mutexes
-	 *     at the DB page level instead of blocking mutexes. That has
-	 *     proven to be a killer for the changelog DB, as this DB is
-	 *     accessed by multiple a reader threads (the repl thread) and
-	 *     writer threads (the server ops threads) usually at the last
-	 *     pages of the DB, due to the sequential nature of the changelog
-	 *     keys. To avoid the test-and-set mutexes, we could use semaphore
-	 *     to serialize the writers and avoid the high mutex contention
-	 *     that SleepyCat is unable to avoid.
-	 * (2) DS 6.2 introduced the semaphore on all platforms (replaced
-	 *     the serial lock used on Windows and Linux described above). 
-	 *     The number of the concurrent writes now is configurable by
-	 *     nsslapd-changelogmaxconcurrentwrites (the server needs to
-	 *     be restarted).
-	 */
-
-	semadir = s_cl5Desc.dbDir;
-#ifdef HPUX
-	/*
-	 * HP sem_open() does not allow pathname component "./" or "../"
-	 * in the semaphore name. For simplicity and to avoid doing
-	 * chdir() in multi-thread environment, current working dir
-	 * (log dir) is used to replace the original semaphore dir
-	 * if it contains "./".
-	 */
-	if ( strstr ( semadir, "./" ) != NULL && getcwd ( cwd, PATH_MAX+1 ) != NULL )
-	{
-		semadir = cwd;
-	}
-#endif
-
-	if ( semadir != NULL )
-	{
-		(*dbFile)->semaName = slapi_ch_smprintf("%s/%s.sema", semadir, replName);
-		slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name_cl,
-			"_cl5NewDBFile - semaphore %s\n", (*dbFile)->semaName);
-		(*dbFile)->sema = PR_OpenSemaphore((*dbFile)->semaName,
-                        PR_SEM_CREATE | PR_SEM_EXCL, 0666,
-                        s_cl5Desc.dbConfig.maxConcurrentWrites );
-		slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name_cl, "_cl5NewDBFile - maxConcurrentWrites=%d\n", s_cl5Desc.dbConfig.maxConcurrentWrites );
-	}
-
-	if ((*dbFile)->sema == NULL )
-	{
-		/* If the semaphore was left around due
-		 * to an unclean exit last time, remove
-		 * and re-create it.
-		 */ 
-		if (PR_GetError() == PR_FILE_EXISTS_ERROR) {
-			PRErrorCode prerr;
-			PR_DeleteSemaphore((*dbFile)->semaName);
-			prerr = PR_GetError();
-			if (PR_SUCCESS != prerr) {
-				slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
-				                "_cl5NewDBFile - PR_DeleteSemaphore: %s; NSPR error - %d\n",
-				                (*dbFile)->semaName ? (*dbFile)->semaName : "(nil)", prerr);
-			}
-			(*dbFile)->sema = PR_OpenSemaphore((*dbFile)->semaName,
-					PR_SEM_CREATE | PR_SEM_EXCL, 0666,
-					s_cl5Desc.dbConfig.maxConcurrentWrites );
-		}
-
-		/* If we still failed to create the semaphore,
-		 * we should just error out. */
-		if ((*dbFile)->sema == NULL )
-		{
-			PRErrorCode prerr = PR_GetError();
-			if (PR_FILE_EXISTS_ERROR == prerr) {
-				slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
-				                "_cl5NewDBFile - PR_OpenSemaphore: %s; sema: 0x%p, NSPR error - %d\n",
-				                (*dbFile)->semaName ? (*dbFile)->semaName : "(nil)", (*dbFile)->sema, prerr);
-				slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
-				                "_cl5NewDBFile - Leftover semaphores may exist.  "
-				                "Run \"ipcs -s\", and remove them with \"ipcrm -s <SEMID>\" if any\n");
-			} else {
-				slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name_cl,
-				                "_cl5NewDBFile - Failed to create semaphore %s; NSPR error - %d\n",
-				                (*dbFile)->semaName ? (*dbFile)->semaName : "(nil)", prerr);
-			}
-			rc = CL5_SYSTEM_ERROR;
-			goto done;
-		}
-	}
 
 	/* compute number of entries in the file */
 	/* ONREPL - to improve performance, we keep entry count in memory
@@ -6326,12 +6228,6 @@ static void _cl5DBCloseFile (void **data)
 	ruv_destroy(&file->maxRUV);
 	ruv_destroy(&file->purgeRUV);
 	file->db = NULL;
-	if (file->sema) {
-		PR_CloseSemaphore (file->sema);
-		PR_DeleteSemaphore (file->semaName);
-		file->sema = NULL;
-	}
-	slapi_ch_free ((void**)&file->semaName);
 
 	slapi_ch_free (data);
 }

+ 0 - 12
ldap/servers/plugins/replication/cl5_api.h

@@ -41,7 +41,6 @@ typedef struct cl5dbconfig
 {
 	size_t	pageSize;			/* page size in bytes */
 	PRInt32	fileMode;			/* file mode */
-	PRUint32 maxConcurrentWrites;	/* max number of concurrent cl writes */
 	char *encryptionAlgorithm;	/* nsslapd-encryptionalgorithm */
 	char *symmetricKey;
 } CL5DBConfig;
@@ -74,17 +73,6 @@ typedef struct cl5entry
 #define CL5_DEFAULT_CONFIG_CACHEMEMSIZE			1048576 /* 1 M bytes */
 #define CL5_DEFAULT_CONFIG_NB_LOCK	1000 /* Number of locks in the lock table of the DB */
 
-/*
- * Small number of concurrent writes degradate the throughput.
- * Large one increases deadlock.
- */
-#ifdef SOLARIS
-#define CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES	10
-#else
-#define CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES	2
-#endif
-
-
 #define CL5_MIN_DB_DBCACHESIZE		524288 /* min 500K bytes */
 #define CL5_MIN_CACHESIZE		500 /* min number of entries */
 #define CL5_MIN_CACHEMEMSIZE		262144 /* min 250K bytes */

+ 0 - 15
ldap/servers/plugins/replication/cl5_config.c

@@ -740,7 +740,6 @@ static changelog5Config * changelog5_dup_config(changelog5Config *config)
 
 	dup->dbconfig.pageSize = config->dbconfig.pageSize;
 	dup->dbconfig.fileMode = config->dbconfig.fileMode;
-	dup->dbconfig.maxConcurrentWrites = config->dbconfig.maxConcurrentWrites;
 
 	return dup;
 }
@@ -813,20 +812,6 @@ static void changelog5_extract_config(Slapi_Entry* entry, changelog5Config *conf
 		config->maxAge = slapi_ch_strdup(CL5_STR_IGNORE);
 	}
 
-	/* 
-	 * Read the Changelog Internal Configuration Parameters for the Changelog DB
-	 */
-	arg = slapi_entry_attr_get_charptr(entry, CONFIG_CHANGELOG_MAX_CONCURRENT_WRITES);
-	if (arg)
-	{
-		config->dbconfig.maxConcurrentWrites = atoi (arg);
-		slapi_ch_free_string(&arg);
-	}
-	if ( config->dbconfig.maxConcurrentWrites <= 0 )
-	{
-		config->dbconfig.maxConcurrentWrites = CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES;
-	}
-
 	/* 
 	 * changelog encryption
 	 */

+ 0 - 1
ldap/servers/plugins/replication/repl_shared.h

@@ -33,7 +33,6 @@
 #define CONFIG_CHANGELOG_COMPACTDB_ATTRIBUTE	"nsslapd-changelogcompactdb-interval"
 #define CONFIG_CHANGELOG_TRIM_ATTRIBUTE	"nsslapd-changelogtrim-interval"
 /* Changelog Internal Configuration Parameters -> Changelog Cache related */
-#define CONFIG_CHANGELOG_MAX_CONCURRENT_WRITES	"nsslapd-changelogmaxconcurrentwrites"
 #define CONFIG_CHANGELOG_ENCRYPTION_ALGORITHM	"nsslapd-encryptionalgorithm"
 #define CONFIG_CHANGELOG_SYMMETRIC_KEY	"nsSymmetricKey"