<commit_before>package com.thinkaurelius.titan.graphdb.configuration;

import com.google.common.collect.Maps;
import com.thinkaurelius.titan.core.*;
import com.thinkaurelius.titan.core.attribute.AttributeHandler;
import com.thinkaurelius.titan.core.attribute.Duration;
import com.thinkaurelius.titan.core.schema.DefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.blueprints.BlueprintsDefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.types.typemaker.DisableDefaultSchemaMaker;
import com.thinkaurelius.titan.util.stats.NumberUtil;
import com.thinkaurelius.titan.diskstorage.util.time.*;
import com.thinkaurelius.titan.diskstorage.configuration.*;
import com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration;
import com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration;
import com.thinkaurelius.titan.diskstorage.idmanagement.ConflictAvoidanceMode;
import com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyColumnValueStoreManager;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures;
import com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingStore;
import com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog;
import com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLogManager;
import com.thinkaurelius.titan.graphdb.database.cache.MetricInstrumentedSchemaCache;
import com.thinkaurelius.titan.graphdb.database.cache.StandardSchemaCache;
import com.thinkaurelius.titan.graphdb.database.cache.SchemaCache;
import com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer;
import com.thinkaurelius.titan.util.encoding.LongEncoding;
import com.thinkaurelius.titan.util.system.NetworkUtil;

import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import javax.annotation.Nullable;
import javax.management.MBeanServerFactory;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.thinkaurelius.titan.diskstorage.Backend;
import com.thinkaurelius.titan.graphdb.database.idassigner.VertexIDAssigner;
import com.thinkaurelius.titan.graphdb.database.serialize.Serializer;
import com.thinkaurelius.titan.graphdb.transaction.StandardTransactionBuilder;
import com.thinkaurelius.titan.util.stats.MetricManager;

/**
 * Provides functionality to configure a {@link com.thinkaurelius.titan.core.TitanGraph} INSTANCE.
 * <p/>
 * <p/>
 * A graph database configuration is uniquely associated with a graph database and must not be used for multiple
 * databases.
 * <p/>
 * After a graph database has been initialized with respect to a configuration, some parameters of graph database
 * configuration may no longer be modifiable.
 *
 * @author <NAME> (<EMAIL>);
 */
public class GraphDatabaseConfiguration {

    private static final Logger log =
            LoggerFactory.getLogger(GraphDatabaseConfiguration.class);


    public static ConfigNamespace ROOT_NS = new ConfigNamespace(null,"root","Root Configuration Namespace for the Titan Graph Database");

    // ################ GENERAL #######################
    // ################################################

    /**
     * Configures the {@link com.thinkaurelius.titan.core.schema.DefaultSchemaMaker} to be used by this graph. If set to 'none', automatic creation of types
     * is disabled.
     */
    public static final ConfigOption<String> AUTO_TYPE = new ConfigOption<String>(ROOT_NS,"autotype",
            "Configures the DefaultTypeMaker to be used by this graph. If set to 'none', automatic creation of types is disabled.",
            ConfigOption.Type.MASKABLE, "blueprints" , new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return s!=null && preregisteredAutoType.containsKey(s);
        }
    });
//    public static final String AUTO_TYPE_KEY = "autotype";
//    public static final String AUTO_TYPE_DEFAULT = "blueprints";

    private static final Map<String, DefaultSchemaMaker> preregisteredAutoType = new HashMap<String, DefaultSchemaMaker>() {{
        put("none", DisableDefaultSchemaMaker.INSTANCE);
        put("blueprints", BlueprintsDefaultSchemaMaker.INSTANCE);
    }};

    /**
     * If this option is enabled, a transaction will retrieval all of a vertex's properties when asking for any property.
     * This will significantly speed up subsequent property lookups on the same vertex, hence this option is enabled by default.
     * Disable this option when the graph contains vertices with very many properties such that retrieving all of them substantially
     * increases latencies compared to a single property retrieval.
     */
    public static final ConfigOption<Boolean> PROPERTY_PREFETCHING = new ConfigOption<Boolean>(ROOT_NS,"fast-property",
            "Whether to pre-fetch all properties on first vertex property access. This can eliminate backend calls on subsequent" +
                    "property access for the same vertex at the expense of retrieving all properties at once.",
            ConfigOption.Type.MASKABLE, Boolean.class);
//    public static final String PROPERTY_PREFETCHING_KEY = "fast-property";

    /**
     * When enabled, Titan will accept user provided vertex ids as long as they are valid Titan vertex ids - see
     * {@link com.thinkaurelius.titan.core.util.TitanId#toVertexId(long)}. When enabled, Titan will now longer allocate and assign
     * ids internally, so all vertices must be added through {@link com.thinkaurelius.titan.core.TitanTransaction#addVertex(Long)}.
     * <p/>
     * Use this setting WITH GREAT CARE since it can easily lead to data corruption and performance issues when not used correctly.
     * This should only ever be used when mapping external to internal ids causes performance issues at very large scale.
     */
    public static final ConfigOption<Boolean> ALLOW_SETTING_VERTEX_ID = new ConfigOption<Boolean>(ROOT_NS,"set-vertex-id",
            "Whether user provided vertex ids should be enabled and Titan's automatic id allocation be disabled. " +
                "Useful when operating Titan in concert with another storage system that assigns long ids but disables some" +
                    "of Titan's advanced features. EXPERT FEATURE - USE WITH GREAT CARE.",
            ConfigOption.Type.FIXED, false);

    public static final ConfigOption<Boolean> FORCE_INDEX_USAGE = new ConfigOption<Boolean>(ROOT_NS,"force-index",
            "Whether Titan should throw an exception if a graph query cannot be answered using an index. Doing so" +
                    "limits the functionality of Titan's graph queries but ensures that slow graph queries are avoided.",
            ConfigOption.Type.MASKABLE, false);
//
//    public static final String ALLOW_SETTING_VERTEX_ID_KEY = "set-vertex-id";
//    public static final boolean ALLOW_SETTING_VERTEX_ID_DEFAULT = false;


    /**
     * When true, Titan will ignore unknown index key fields in queries.
     */
    public static final ConfigOption<Boolean> IGNORE_UNKNOWN_INDEX_FIELD = new ConfigOption<Boolean>(ROOT_NS, "ignore-unknown-index-key",
            "Whether to ignore undefined types encountered in user-provided index queries",
            ConfigOption.Type.MASKABLE, false);
//    public static final String IGNORE_UNKNOWN_INDEX_FIELD_KEY = "ignore-unknown-index-key";
//    public static final boolean IGNORE_UNKNOWN_INDEX_FIELD_DEFAULT = false;

    public static final String UKNOWN_FIELD_NAME = "unknown_key";


    public static final ConfigOption<Timestamps> TIMESTAMP_PROVIDER = new ConfigOption<Timestamps>(ROOT_NS, "timestamps",
            "The timestamp resolution to use when writing to storage and indices",
            ConfigOption.Type.FIXED, Timestamps.MICRO);


    public static final ConfigOption<Boolean> SYSTEM_LOG_TRANSACTIONS = new ConfigOption<Boolean>(ROOT_NS,"log-tx",
            "Whether transaction mutations should be logged to Titan's system log",
            ConfigOption.Type.GLOBAL, true);

    public static final ConfigOption<String> UNIQUE_INSTANCE_ID = new ConfigOption<String>(ROOT_NS,"unique-instance-id",
            "Unique identifier for this Titan instance.  This must be unique among all instances " +
            "concurrently accessing the same stores or indexes.  It's automatically generated by " +
            "concatenating the hostname, process id, and a static (process-wide) counter. " +
            "Leaving it unset is recommended.",
            ConfigOption.Type.LOCAL, String.class);


    public static final ConfigOption<Short> UNIQUE_INSTANCE_ID_SUFFIX = new ConfigOption<Short>(ROOT_NS,"unique-instance-id-suffix",
            "When this is set and " + UNIQUE_INSTANCE_ID.getName() + " is not, this Titan " +
            "instance's unique identifier is generated by concatenating the hostname to the " +
            "provided number.  This is a legacy option which is currently only useful if the JVM's " +
            "ManagementFactory.getRuntimeMXBean().getName() is not unique between processes.",
            ConfigOption.Type.LOCAL, Short.class);
<commit_msg>Disable log-tx by default<commit_after>package com.thinkaurelius.titan.graphdb.configuration;

import com.google.common.collect.Maps;
import com.thinkaurelius.titan.core.*;
import com.thinkaurelius.titan.core.attribute.AttributeHandler;
import com.thinkaurelius.titan.core.attribute.Duration;
import com.thinkaurelius.titan.core.schema.DefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.blueprints.BlueprintsDefaultSchemaMaker;
import com.thinkaurelius.titan.graphdb.types.typemaker.DisableDefaultSchemaMaker;
import com.thinkaurelius.titan.util.stats.NumberUtil;
import com.thinkaurelius.titan.diskstorage.util.time.*;
import com.thinkaurelius.titan.diskstorage.configuration.*;
import com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration;
import com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration;
import com.thinkaurelius.titan.diskstorage.idmanagement.ConflictAvoidanceMode;
import com.thinkaurelius.titan.diskstorage.idmanagement.ConsistentKeyIDAuthority;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyColumnValueStoreManager;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures;
import com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingStore;
import com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLog;
import com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLogManager;
import com.thinkaurelius.titan.graphdb.database.cache.MetricInstrumentedSchemaCache;
import com.thinkaurelius.titan.graphdb.database.cache.StandardSchemaCache;
import com.thinkaurelius.titan.graphdb.database.cache.SchemaCache;
import com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer;
import com.thinkaurelius.titan.util.encoding.LongEncoding;
import com.thinkaurelius.titan.util.system.NetworkUtil;

import info.ganglia.gmetric4j.gmetric.GMetric.UDPAddressingMode;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import javax.annotation.Nullable;
import javax.management.MBeanServerFactory;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.thinkaurelius.titan.diskstorage.Backend;
import com.thinkaurelius.titan.graphdb.database.idassigner.VertexIDAssigner;
import com.thinkaurelius.titan.graphdb.database.serialize.Serializer;
import com.thinkaurelius.titan.graphdb.transaction.StandardTransactionBuilder;
import com.thinkaurelius.titan.util.stats.MetricManager;

/**
 * Provides functionality to configure a {@link com.thinkaurelius.titan.core.TitanGraph} INSTANCE.
 * <p/>
 * <p/>
 * A graph database configuration is uniquely associated with a graph database and must not be used for multiple
 * databases.
 * <p/>
 * After a graph database has been initialized with respect to a configuration, some parameters of graph database
 * configuration may no longer be modifiable.
 *
 * @author <NAME> (<EMAIL>);
 */
public class GraphDatabaseConfiguration {

    private static final Logger log =
            LoggerFactory.getLogger(GraphDatabaseConfiguration.class);


    public static ConfigNamespace ROOT_NS = new ConfigNamespace(null,"root","Root Configuration Namespace for the Titan Graph Database");

    // ################ GENERAL #######################
    // ################################################

    /**
     * Configures the {@link com.thinkaurelius.titan.core.schema.DefaultSchemaMaker} to be used by this graph. If set to 'none', automatic creation of types
     * is disabled.
     */
    public static final ConfigOption<String> AUTO_TYPE = new ConfigOption<String>(ROOT_NS,"autotype",
            "Configures the DefaultTypeMaker to be used by this graph. If set to 'none', automatic creation of types is disabled.",
            ConfigOption.Type.MASKABLE, "blueprints" , new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return s!=null && preregisteredAutoType.containsKey(s);
        }
    });
//    public static final String AUTO_TYPE_KEY = "autotype";
//    public static final String AUTO_TYPE_DEFAULT = "blueprints";

    private static final Map<String, DefaultSchemaMaker> preregisteredAutoType = new HashMap<String, DefaultSchemaMaker>() {{
        put("none", DisableDefaultSchemaMaker.INSTANCE);
        put("blueprints", BlueprintsDefaultSchemaMaker.INSTANCE);
    }};

    /**
     * If this option is enabled, a transaction will retrieval all of a vertex's properties when asking for any property.
     * This will significantly speed up subsequent property lookups on the same vertex, hence this option is enabled by default.
     * Disable this option when the graph contains vertices with very many properties such that retrieving all of them substantially
     * increases latencies compared to a single property retrieval.
     */
    public static final ConfigOption<Boolean> PROPERTY_PREFETCHING = new ConfigOption<Boolean>(ROOT_NS,"fast-property",
            "Whether to pre-fetch all properties on first vertex property access. This can eliminate backend calls on subsequent" +
                    "property access for the same vertex at the expense of retrieving all properties at once.",
            ConfigOption.Type.MASKABLE, Boolean.class);
//    public static final String PROPERTY_PREFETCHING_KEY = "fast-property";

    /**
     * When enabled, Titan will accept user provided vertex ids as long as they are valid Titan vertex ids - see
     * {@link com.thinkaurelius.titan.core.util.TitanId#toVertexId(long)}. When enabled, Titan will now longer allocate and assign
     * ids internally, so all vertices must be added through {@link com.thinkaurelius.titan.core.TitanTransaction#addVertex(Long)}.
     * <p/>
     * Use this setting WITH GREAT CARE since it can easily lead to data corruption and performance issues when not used correctly.
     * This should only ever be used when mapping external to internal ids causes performance issues at very large scale.
     */
    public static final ConfigOption<Boolean> ALLOW_SETTING_VERTEX_ID = new ConfigOption<Boolean>(ROOT_NS,"set-vertex-id",
            "Whether user provided vertex ids should be enabled and Titan's automatic id allocation be disabled. " +
                "Useful when operating Titan in concert with another storage system that assigns long ids but disables some" +
                    "of Titan's advanced features. EXPERT FEATURE - USE WITH GREAT CARE.",
            ConfigOption.Type.FIXED, false);

    public static final ConfigOption<Boolean> FORCE_INDEX_USAGE = new ConfigOption<Boolean>(ROOT_NS,"force-index",
            "Whether Titan should throw an exception if a graph query cannot be answered using an index. Doing so" +
                    "limits the functionality of Titan's graph queries but ensures that slow graph queries are avoided.",
            ConfigOption.Type.MASKABLE, false);
//
//    public static final String ALLOW_SETTING_VERTEX_ID_KEY = "set-vertex-id";
//    public static final boolean ALLOW_SETTING_VERTEX_ID_DEFAULT = false;


    /**
     * When true, Titan will ignore unknown index key fields in queries.
     */
    public static final ConfigOption<Boolean> IGNORE_UNKNOWN_INDEX_FIELD = new ConfigOption<Boolean>(ROOT_NS, "ignore-unknown-index-key",
            "Whether to ignore undefined types encountered in user-provided index queries",
            ConfigOption.Type.MASKABLE, false);
//    public static final String IGNORE_UNKNOWN_INDEX_FIELD_KEY = "ignore-unknown-index-key";
//    public static final boolean IGNORE_UNKNOWN_INDEX_FIELD_DEFAULT = false;

    public static final String UKNOWN_FIELD_NAME = "unknown_key";


    public static final ConfigOption<Timestamps> TIMESTAMP_PROVIDER = new ConfigOption<Timestamps>(ROOT_NS, "timestamps",
            "The timestamp resolution to use when writing to storage and indices",
            ConfigOption.Type.FIXED, Timestamps.MICRO);


    public static final ConfigOption<Boolean> SYSTEM_LOG_TRANSACTIONS = new ConfigOption<Boolean>(ROOT_NS,"log-tx",
            "Whether transaction mutations should be logged to Titan's system log",
            ConfigOption.Type.GLOBAL, false);

    public static final ConfigOption<String> UNIQUE_INSTANCE_ID = new ConfigOption<String>(ROOT_NS,"unique-instance-id",
            "Unique identifier for this Titan instance.  This must be unique among all instances " +
            "concurrently accessing the same stores or indexes.  It's automatically generated by " +
            "concatenating the hostname, process id, and a static (process-wide) counter. " +
            "Leaving it unset is recommended.",
            ConfigOption.Type.LOCAL, String.class);


    public static final ConfigOption<Short> UNIQUE_INSTANCE_ID_SUFFIX = new ConfigOption<Short>(ROOT_NS,"unique-instance-id-suffix",
            "When this is set and " + UNIQUE_INSTANCE_ID.getName() + " is not, this Titan " +
            "instance's unique identifier is generated by concatenating the hostname to the " +
            "provided number.  This is a legacy option which is currently only useful if the JVM's " +
            "ManagementFactory.getRuntimeMXBean().getName() is not unique between processes.",
            ConfigOption.Type.LOCAL, Short.class);

{'fraction_non_alphanumeric': 0.08988357050452782, 'fraction_numerical': 0.00041397153945666235, 'mean_word_length': 4.199354317998385, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1469953', 'n_tokens_mistral': 5304, 'n_tokens_neox': 5153, 'n_words': 1501}