internal override NumberLayout Layout(StoreIndexDescriptor descriptor, File storeFile) { // split like this due to legacy reasons, there are old stores out there with these different identifiers switch (descriptor.Type()) { case GENERAL: return(new NumberLayoutNonUnique()); case UNIQUE: return(new NumberLayoutUnique()); default: throw new System.ArgumentException("Unknown index type " + descriptor.Type()); } }
/// <summary> /// Serialize the provided IndexRule onto the target buffer /// </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor to serialize </param> /// <exception cref="IllegalStateException"> if the StoreIndexDescriptor is of type unique, but the owning constrain has not been set </exception> public static sbyte[] Serialize(StoreIndexDescriptor indexDescriptor) { ByteBuffer target = ByteBuffer.allocate(LengthOf(indexDescriptor)); target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID); target.put(INDEX_RULE); IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); UTF8.putEncodedStringInto(providerDescriptor.Key, target); UTF8.putEncodedStringInto(providerDescriptor.Version, target); switch (indexDescriptor.Type()) { case GENERAL: target.put(GENERAL_INDEX); break; case UNIQUE: target.put(UNIQUE_INDEX); // The owning constraint can be null. See IndexRule.getOwningConstraint() long?owningConstraint = indexDescriptor.OwningConstraint; target.putLong(owningConstraint == null ? NO_OWNING_CONSTRAINT_YET : owningConstraint); break; default: throw new System.NotSupportedException(format("Got unknown index descriptor type '%s'.", indexDescriptor.Type())); } indexDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target)); UTF8.putEncodedStringInto(indexDescriptor.Name, target); return(target.array()); }
public override IndexPopulator GetPopulator(StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory) { SchemaIndex luceneIndex = LuceneSchemaIndexBuilder.Create(descriptor, _config).withFileSystem(_fileSystem).withOperationalMode(_operationalMode).withSamplingConfig(samplingConfig).withIndexStorage(GetIndexStorage(descriptor.Id)).withWriterConfig(IndexWriterConfigs.population).build(); if (luceneIndex.ReadOnly) { throw new System.NotSupportedException("Can't create populator for read only index"); } if (descriptor.Type() == UNIQUE) { return(new UniqueLuceneIndexPopulator(luceneIndex, descriptor)); } else { return(new NonUniqueLuceneIndexPopulator(luceneIndex, samplingConfig)); } }
/// <summary> /// Compute the byte size needed to serialize the provided IndexRule using serialize. </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor </param> /// <returns> the byte size of StoreIndexDescriptor </returns> internal static int LengthOf(StoreIndexDescriptor indexDescriptor) { int length = 4; // legacy label or relType id length += 1; // schema rule type IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Key); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Version); length += 1; // index type if (indexDescriptor.Type() == IndexDescriptor.Type.UNIQUE) { length += 8; // owning constraint id } length += indexDescriptor.Schema().computeWith(schemaSizeComputer); length += UTF8.computeRequiredByteBufferSize(indexDescriptor.Name); return(length); }