DWORD VmDirLoadIndex( BOOLEAN bFirstboot ) { DWORD dwError = 0; DWORD i = 0; PVDIR_SCHEMA_CTX pSchemaCtx = NULL; PVDIR_SCHEMA_AT_DESC* ppATDescList = NULL; PVDIR_INDEX_CFG pIndexCfg = NULL; if (bFirstboot) { // Firstboot should use only the default indices // Nothing to load goto cleanup; } dwError = VmDirSchemaCtxAcquire(&pSchemaCtx); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirSchemaAttrList(pSchemaCtx, &ppATDescList); BAIL_ON_VMDIR_ERROR(dwError); // Identify non-default indices by their searchFlags and open them for (i = 0; ppATDescList[i]; i++) { if ((ppATDescList[i]->dwSearchFlags & 1) && !VmDirIndexIsDefault(ppATDescList[i]->pszName)) { dwError = VmDirCustomIndexCfgInit(ppATDescList[i], &pIndexCfg); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirIndexOpen(pIndexCfg); BAIL_ON_VMDIR_ERROR(dwError); pIndexCfg = NULL; } } cleanup: VMDIR_SAFE_FREE_MEMORY(ppATDescList); VmDirSchemaCtxRelease(pSchemaCtx); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError ); VmDirFreeIndexCfg(pIndexCfg); goto cleanup; }
DWORD VmDirIndexLibInit( PVMDIR_MUTEX pModMutex ) { static VDIR_DEFAULT_INDEX_CFG defIdx[] = VDIR_INDEX_INITIALIZER; DWORD dwError = 0; DWORD i = 0; PSTR pszLastOffset = NULL; ENTRYID maxEId = 0; VDIR_BACKEND_CTX beCtx = {0}; BOOLEAN bHasTxn = FALSE; PVDIR_INDEX_CFG pIndexCfg = NULL; PVDIR_SCHEMA_CTX pSchemaCtx = NULL; PVDIR_SCHEMA_AT_DESC pATDesc = NULL; if (!pModMutex) { dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } // pModMutex refers to gVdirSchemaGlobals.cacheModMutex, // so do not free it during shutdown gVdirIndexGlobals.mutex = pModMutex; dwError = VmDirAllocateCondition(&gVdirIndexGlobals.cond); BAIL_ON_VMDIR_ERROR(dwError); dwError = LwRtlCreateHashMap( &gVdirIndexGlobals.pIndexCfgMap, LwRtlHashDigestPstrCaseless, LwRtlHashEqualPstrCaseless, NULL); BAIL_ON_VMDIR_ERROR(dwError); beCtx.pBE = VmDirBackendSelect(NULL); dwError = beCtx.pBE->pfnBETxnBegin(&beCtx, VDIR_BACKEND_TXN_WRITE); BAIL_ON_VMDIR_ERROR(dwError); bHasTxn = TRUE; // get fields to continue indexing from where it left last time dwError = beCtx.pBE->pfnBEUniqKeyGetValue( &beCtx, INDEX_LAST_OFFSET_KEY, &pszLastOffset); if (dwError) { dwError = beCtx.pBE->pfnBEMaxEntryId(&maxEId); BAIL_ON_VMDIR_ERROR(dwError); if (maxEId == ENTRY_ID_SEQ_INITIAL_VALUE) { gVdirIndexGlobals.bFirstboot = TRUE; } else { gVdirIndexGlobals.bLegacyDB = TRUE; } // set index_last_offset = -1 to indicate indexing has started gVdirIndexGlobals.offset = -1; dwError = beCtx.pBE->pfnBEUniqKeySetValue( &beCtx, INDEX_LAST_OFFSET_KEY, "-1"); BAIL_ON_VMDIR_ERROR(dwError); } else { dwError = VmDirStringToINT64(pszLastOffset, NULL, &gVdirIndexGlobals.offset); BAIL_ON_VMDIR_ERROR(dwError); } dwError = beCtx.pBE->pfnBETxnCommit(&beCtx); BAIL_ON_VMDIR_ERROR(dwError); bHasTxn = FALSE; dwError = VmDirSchemaCtxAcquire(&pSchemaCtx); BAIL_ON_VMDIR_ERROR(dwError); // open default indices for (i = 0; defIdx[i].pszAttrName; i++) { dwError = VmDirDefaultIndexCfgInit(&defIdx[i], &pIndexCfg); BAIL_ON_VMDIR_ERROR(dwError); // update attribute types in schema cache with their index info dwError = VmDirSchemaAttrNameToDescriptor( pSchemaCtx, pIndexCfg->pszAttrName, &pATDesc); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirIndexCfgGetAllScopesInStrArray( pIndexCfg, &pATDesc->ppszUniqueScopes); BAIL_ON_VMDIR_ERROR(dwError); pATDesc->dwSearchFlags |= 1; // for free later pATDesc->pLdapAt->ppszUniqueScopes = pATDesc->ppszUniqueScopes; pATDesc->pLdapAt->dwSearchFlags = pATDesc->dwSearchFlags; dwError = VmDirIndexOpen(pIndexCfg); BAIL_ON_VMDIR_ERROR(dwError); pIndexCfg = NULL; } // VMIT support dwError = VmDirIndexLibInitVMIT(); BAIL_ON_VMDIR_ERROR(dwError); dwError = InitializeIndexingThread(); BAIL_ON_VMDIR_ERROR(dwError); cleanup: if (bHasTxn) { beCtx.pBE->pfnBETxnAbort(&beCtx); } VmDirBackendCtxContentFree(&beCtx); VmDirSchemaCtxRelease(pSchemaCtx); VMDIR_SAFE_FREE_MEMORY(pszLastOffset); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError); VmDirFreeIndexCfg(pIndexCfg); goto cleanup; }