Code review comment: Many local variables here that are not part of cleanup can be moved a lot closer to their actual usage or even omitted when just passing the new object to a constructor directly.

Code under review:
public RocksDBKeyedStateBackend<K> build() throws BackendBuildingException {
		RocksDBKeyedStateBackend<K> backend = null;
		RocksDBWriteBatchWrapper writeBatchWrapper = null;
		ColumnFamilyHandle defaultColumnFamilyHandle = null;
		RocksDBNativeMetricMonitor nativeMetricMonitor = nativeMetricOptions.isEnabled() ?
			new RocksDBNativeMetricMonitor(nativeMetricOptions, metricGroup) : null;
		CloseableRegistry cancelStreamRegistry = new CloseableRegistry();
		
		WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
		LinkedHashMap<String, StateColumnFamilyHandle> kvStateInformation = new LinkedHashMap<>();
		ResourceGuard rocksDBResourceGuard = new ResourceGuard();
		RocksDB db;
		AbstractRocksDBRestoreOperation restoreOperation = null;
		
		SnapshotStrategy snapshotStrategy = null;
		UUID backendUID = UUID.randomUUID();
		SortedMap<Long, Set<StateHandleID>> materializedSstFiles = new TreeMap<>();
		long lastCompletedCheckpointId = -1L;
		
		int keyGroupPrefixBytes = RocksDBKeySerializationUtils.computeRequiredBytesInKeyGroupPrefix(numberOfKeyGroups);
		try {
			prepareDirectories();

			if (injectedTestDB != null) {
				db = injectedTestDB;
			} else {
				restoreOperation = getRocksDBRestoreOperation(
					keyGroupPrefixBytes, cancelStreamRegistry, kvStateInformation, nativeMetricMonitor);
				RocksDBRestoreResult restoreResult = restoreOperation.restore(restoreStateHandles, null);
				db = restoreResult.getDb();
				backendUID = restoreResult.getBackendUID();
				materializedSstFiles = restoreResult.getRestoredSstFiles();
				lastCompletedCheckpointId = restoreResult.getLastCompletedCheckpointId();
				defaultColumnFamilyHandle = restoreResult.getDefaultColumnFamilyHandle();
			}

			writeBatchWrapper = new RocksDBWriteBatchWrapper(db, writeOptions);
			
			
			
			RocksDBSerializedCompositeKeyBuilder sharedRocksKeyBuilder = new RocksDBSerializedCompositeKeyBuilder<>(
				keySerializerProvider.currentSchemaSerializer(),
				keyGroupPrefixBytes,
				32);
			
			snapshotStrategy = initializeSnapshotStrategy(cancelStreamRegistry, rocksDBResourceGuard,
				kvStateInformation, keyGroupPrefixBytes, db, backendUID, materializedSstFiles, lastCompletedCheckpointId);
			
			PriorityQueueSetFactory priorityQueueFactory = initPriorityQueueFactory(
				keyGroupPrefixBytes, kvStateInformation, db, writeBatchWrapper, nativeMetricMonitor);

			backend = new RocksDBKeyedStateBackend<>(
				this.operatorIdentifier,
				this.userCodeClassLoader,
				this.instanceBasePath,
				this.dbOptions,
				this.columnFamilyOptions,
				this.kvStateRegistry,
				this.keySerializerProvider,
				this.numberOfKeyGroups,
				this.keyGroupRange,
				this.executionConfig,
				this.numberOfTransferingThreads,
				this.ttlTimeProvider,
				db,
				kvStateInformation,
				keyGroupPrefixBytes,
				cancelStreamRegistry,
				this.keyGroupCompressionDecorator,
				rocksDBResourceGuard,
				snapshotStrategy.checkpointSnapshotStrategy,
				snapshotStrategy.savepointSnapshotStrategy,
				writeBatchWrapper,
				defaultColumnFamilyHandle,
				nativeMetricMonitor,
				sharedRocksKeyBuilder,
				priorityQueueFactory
			);

			return backend;
		} catch (Throwable e) {
			
			if (backend != null) {
				backend.dispose();
			} else {
				IOUtils.closeQuietly(cancelStreamRegistry);
				IOUtils.closeQuietly(writeBatchWrapper);
				IOUtils.closeQuietly(defaultColumnFamilyHandle);
				IOUtils.closeQuietly(nativeMetricMonitor);
				for (StateColumnFamilyHandle columnFamilyHandle : kvStateInformation.values()) {
					IOUtils.closeQuietly(columnFamilyHandle.getColumnFamilyHandle());
				}
				if (restoreOperation != null) {
					
					IOUtils.closeQuietly(restoreOperation.getDefaultColumnFamilyHandle());
					IOUtils.closeQuietly(restoreOperation.getDb());
				}
				IOUtils.closeQuietly(columnFamilyOptions);
				IOUtils.closeQuietly(dbOptions);
				IOUtils.closeQuietly(writeOptions);
			}
			try {
				FileUtils.deleteDirectory(instanceBasePath);
			} catch (Exception ex) {
				LOG.warn("Failed to instance base path for RocksDB: " + instanceBasePath, ex);
			}
			
			if (e instanceof BackendBuildingException) {
				throw (BackendBuildingException) e;
			} else {
				String errMsg = "Caught unexpected exception.";
				LOG.error(errMsg, e);
				throw new BackendBuildingException(errMsg, e);
			}
		}
	}

Line commented on: LinkedHashMap<String, StateColumnFamilyHandle> kvStateInformation = new LinkedHashMap<>();

Revised code:
public RocksDBKeyedStateBackend<K> build() throws BackendBuildingException {
		RocksDBWriteBatchWrapper writeBatchWrapper = null;
		ColumnFamilyHandle defaultColumnFamilyHandle = null;
		RocksDBNativeMetricMonitor nativeMetricMonitor = null;
		CloseableRegistry cancelStreamRegistry = new CloseableRegistry();
		
		WriteOptions writeOptions = new WriteOptions().setDisableWAL(true);
		LinkedHashMap<String, RocksDBKeyedStateBackend.RocksDbKvStateInfo> kvStateInformation = new LinkedHashMap<>();
		RocksDB db = null;
		AbstractRocksDBRestoreOperation restoreOperation = null;
		RocksDbTtlCompactFiltersManager ttlCompactFiltersManager =
			new RocksDbTtlCompactFiltersManager(enableTtlCompactionFilter);

		ResourceGuard rocksDBResourceGuard = new ResourceGuard();
		SnapshotStrategy<K> snapshotStrategy;
		PriorityQueueSetFactory priorityQueueFactory;
		RocksDBSerializedCompositeKeyBuilder<K> sharedRocksKeyBuilder;
		
		int keyGroupPrefixBytes = RocksDBKeySerializationUtils.computeRequiredBytesInKeyGroupPrefix(numberOfKeyGroups);
		try {
			
			UUID backendUID = UUID.randomUUID();
			SortedMap<Long, Set<StateHandleID>> materializedSstFiles = new TreeMap<>();
			long lastCompletedCheckpointId = -1L;
			if (injectedTestDB != null) {
				db = injectedTestDB;
				defaultColumnFamilyHandle = injectedDefaultColumnFamilyHandle;
				nativeMetricMonitor = nativeMetricOptions.isEnabled() ?
					new RocksDBNativeMetricMonitor(nativeMetricOptions, metricGroup, db) : null;
			} else {
				prepareDirectories();
				restoreOperation = getRocksDBRestoreOperation(
					keyGroupPrefixBytes, cancelStreamRegistry, kvStateInformation, ttlCompactFiltersManager);
				RocksDBRestoreResult restoreResult = restoreOperation.restore();
				db = restoreResult.getDb();
				defaultColumnFamilyHandle = restoreResult.getDefaultColumnFamilyHandle();
				nativeMetricMonitor = restoreResult.getNativeMetricMonitor();
				if (restoreOperation instanceof RocksDBIncrementalRestoreOperation) {
					backendUID = restoreResult.getBackendUID();
					materializedSstFiles = restoreResult.getRestoredSstFiles();
					lastCompletedCheckpointId = restoreResult.getLastCompletedCheckpointId();
				}
			}

			writeBatchWrapper = new RocksDBWriteBatchWrapper(db, writeOptions);
			
			
			
			sharedRocksKeyBuilder = new RocksDBSerializedCompositeKeyBuilder<>(
				keySerializerProvider.currentSchemaSerializer(),
				keyGroupPrefixBytes,
				32);
			
			snapshotStrategy = initializeSavepointAndCheckpointStrategies(cancelStreamRegistry, rocksDBResourceGuard,
				kvStateInformation, keyGroupPrefixBytes, db, backendUID, materializedSstFiles, lastCompletedCheckpointId);
			
			priorityQueueFactory = initPriorityQueueFactory(keyGroupPrefixBytes, kvStateInformation, db,
				writeBatchWrapper, nativeMetricMonitor);
		} catch (Throwable e) {
			
			List<ColumnFamilyOptions> columnFamilyOptions = new ArrayList<>(kvStateInformation.values().size());
			IOUtils.closeQuietly(cancelStreamRegistry);
			IOUtils.closeQuietly(writeBatchWrapper);
			RocksDBOperationUtils.addColumnFamilyOptionsToCloseLater(columnFamilyOptions, defaultColumnFamilyHandle);
			IOUtils.closeQuietly(defaultColumnFamilyHandle);
			IOUtils.closeQuietly(nativeMetricMonitor);
			for (RocksDBKeyedStateBackend.RocksDbKvStateInfo kvStateInfo : kvStateInformation.values()) {
				RocksDBOperationUtils.addColumnFamilyOptionsToCloseLater(columnFamilyOptions, kvStateInfo.columnFamilyHandle);
				IOUtils.closeQuietly(kvStateInfo.columnFamilyHandle);
			}
			IOUtils.closeQuietly(db);
			
			IOUtils.closeQuietly(restoreOperation);
			IOUtils.closeAllQuietly(columnFamilyOptions);
			IOUtils.closeQuietly(dbOptions);
			IOUtils.closeQuietly(writeOptions);
			ttlCompactFiltersManager.disposeAndClearRegisteredCompactionFactories();
			kvStateInformation.clear();
			try {
				FileUtils.deleteDirectory(instanceBasePath);
			} catch (Exception ex) {
				LOG.warn("Failed to instance base path for RocksDB: " + instanceBasePath, ex);
			}
			
			if (e instanceof BackendBuildingException) {
				throw (BackendBuildingException) e;
			} else {
				String errMsg = "Caught unexpected exception.";
				LOG.error(errMsg, e);
				throw new BackendBuildingException(errMsg, e);
			}
		}
		return new RocksDBKeyedStateBackend<>(
			this.operatorIdentifier,
			this.userCodeClassLoader,
			this.instanceBasePath,
			this.dbOptions,
			columnFamilyOptionsFactory,
			this.kvStateRegistry,
			this.keySerializerProvider,
			this.numberOfKeyGroups,
			this.keyGroupRange,
			this.executionConfig,
			this.numberOfTransferingThreads,
			this.ttlTimeProvider,
			db,
			kvStateInformation,
			keyGroupPrefixBytes,
			cancelStreamRegistry,
			this.keyGroupCompressionDecorator,
			rocksDBResourceGuard,
			snapshotStrategy.checkpointSnapshotStrategy,
			snapshotStrategy.savepointSnapshotStrategy,
			writeBatchWrapper,
			defaultColumnFamilyHandle,
			nativeMetricMonitor,
			sharedRocksKeyBuilder,
			priorityQueueFactory,
			ttlCompactFiltersManager
		);
	}