static DWORD _VmDirPagedSearchWorkerThread( PVOID pArg ) { PVDIR_PAGED_SEARCH_RECORD pSearchRecord = (PVDIR_PAGED_SEARCH_RECORD)pArg; DWORD dwError = 0; PVDIR_PAGED_SEARCH_ENTRY_LIST pEntryIdList = NULL; VDIR_OPERATION searchOp = {0}; VmDirDropThreadPriority(DEFAULT_THREAD_PRIORITY_DELTA); dwError = VmDirInitStackOperation( &searchOp, VDIR_OPERATION_TYPE_INTERNAL, LDAP_REQ_SEARCH, NULL); BAIL_ON_VMDIR_ERROR(dwError); searchOp.pBEIF = VmDirBackendSelect(NULL); searchOp.request.searchReq.filter = pSearchRecord->pFilter; while (pSearchRecord->dwCandidatesProcessed < (DWORD)pSearchRecord->pTotalCandidates->size) { dwError = _VmDirPagedSearchEntryListAlloc(pSearchRecord, &pEntryIdList); BAIL_ON_VMDIR_ERROR(dwError); _VmDirPagedSearchProcessEntries(&searchOp, pSearchRecord, pEntryIdList); if (pEntryIdList->dwCount == 0) { _VmDirPagedSearchEntryListFree(pEntryIdList); } else { dwError = VmDirPagedSearchCacheAddData(pSearchRecord, pEntryIdList); BAIL_ON_VMDIR_ERROR(dwError); } } _VmDirPagedSearchCacheWaitForClientCompletion(pSearchRecord); cleanup: // This will be freed when the pSearchRecord is released. searchOp.request.searchReq.filter = NULL; VmDirFreeOperationContent(&searchOp); _DerefPagedSearchRecord(pSearchRecord); return dwError; error: goto cleanup; }
DWORD VmDirIndexingThreadFun( PVOID pArg ) { DWORD dwError = 0; BOOLEAN bInLock = FALSE; BOOLEAN bResume = FALSE; VDIR_SERVER_STATE vmdirState = VMDIRD_STATE_UNDEFINED; PVDIR_INDEXING_TASK pTask = NULL; VmDirDropThreadPriority(DEFAULT_THREAD_PRIORITY_DELTA); resume: while (1) { vmdirState = VmDirdState(); if (vmdirState == VMDIRD_STATE_SHUTDOWN) { break; } else if (vmdirState != VMDIRD_STATE_NORMAL) { VmDirSleep(1000); continue; } VMDIR_LOCK_MUTEX(bInLock, gVdirIndexGlobals.mutex); if (!bResume) { PVDIR_INDEX_UPD pIndexUpd = gVdirIndexGlobals.pIndexUpd; // record current progress dwError = VmDirIndexingTaskRecordProgress(pTask, pIndexUpd); BAIL_ON_VMDIR_ERROR(dwError); // apply index updates dwError = VmDirIndexUpdApply(pIndexUpd); BAIL_ON_VMDIR_ERROR(dwError); VmDirIndexUpdFree(pIndexUpd); gVdirIndexGlobals.pIndexUpd = NULL; // compute new task VmDirFreeIndexingTask(pTask); dwError = VmDirIndexingTaskCompute(&pTask); BAIL_ON_VMDIR_ERROR(dwError); } if (VmDirIndexingTaskIsNoop(pTask)) { dwError = VmDirConditionWait( gVdirIndexGlobals.cond, gVdirIndexGlobals.mutex); BAIL_ON_VMDIR_ERROR(dwError); continue; } VMDIR_UNLOCK_MUTEX(bInLock, gVdirIndexGlobals.mutex); dwError = VmDirIndexingTaskPopulateIndices(pTask); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirIndexingTaskValidateScopes(pTask); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirIndexingTaskDeleteIndices(pTask); BAIL_ON_VMDIR_ERROR(dwError); bResume = FALSE; } cleanup: VMDIR_UNLOCK_MUTEX(bInLock, gVdirIndexGlobals.mutex); VmDirFreeIndexingTask(pTask); return dwError; error: if (dwError == ERROR_INVALID_STATE) { bResume = TRUE; goto resume; } else { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError ); } goto cleanup; }