Search in sources :

Example 1 with HintedHandoffStrategyType

use of voldemort.store.slop.strategy.HintedHandoffStrategyType in project voldemort by voldemort.

the class StoreDefinitionsMapper method readStore.

@SuppressWarnings("unchecked")
private static StoreDefinition readStore(Element store) {
    String name = store.getChildText(STORE_NAME_ELMT);
    String storeType = store.getChildText(STORE_PERSISTENCE_ELMT);
    String description = store.getChildText(STORE_DESCRIPTION_ELMT);
    String ownerText = store.getChildText(STORE_OWNERS_ELMT);
    List<String> owners = Lists.newArrayList();
    if (ownerText != null) {
        for (String owner : Utils.COMMA_SEP.split(ownerText.trim())) if (owner.trim().length() > 0)
            owners.add(owner);
    }
    int replicationFactor = Integer.parseInt(store.getChildText(STORE_REPLICATION_FACTOR_ELMT));
    HashMap<Integer, Integer> zoneReplicationFactor = null;
    Element zoneReplicationFactorNode = store.getChild(STORE_ZONE_REPLICATION_FACTOR_ELMT);
    if (zoneReplicationFactorNode != null) {
        zoneReplicationFactor = new HashMap<Integer, Integer>();
        for (Element node : (List<Element>) zoneReplicationFactorNode.getChildren(STORE_REPLICATION_FACTOR_ELMT)) {
            int zone = Integer.parseInt(node.getAttribute(STORE_ZONE_ID_ELMT).getValue());
            int repFactor = Integer.parseInt(node.getText());
            zoneReplicationFactor.put(zone, repFactor);
        }
    }
    String zoneCountReadsStr = store.getChildText(STORE_ZONE_COUNT_READS);
    Integer zoneCountReads = null;
    if (zoneCountReadsStr != null)
        zoneCountReads = Integer.parseInt(zoneCountReadsStr);
    String zoneCountWritesStr = store.getChildText(STORE_ZONE_COUNT_WRITES);
    Integer zoneCountWrites = null;
    if (zoneCountWritesStr != null)
        zoneCountWrites = Integer.parseInt(zoneCountWritesStr);
    int requiredReads = Integer.parseInt(store.getChildText(STORE_REQUIRED_READS_ELMT));
    int requiredWrites = Integer.parseInt(store.getChildText(STORE_REQUIRED_WRITES_ELMT));
    String preferredReadsStr = store.getChildText(STORE_PREFERRED_READS_ELMT);
    Integer preferredReads = null;
    if (preferredReadsStr != null)
        preferredReads = Integer.parseInt(preferredReadsStr);
    String preferredWritesStr = store.getChildText(STORE_PREFERRED_WRITES_ELMT);
    Integer preferredWrites = null;
    if (preferredWritesStr != null)
        preferredWrites = Integer.parseInt(preferredWritesStr);
    SerializerDefinition keySerializer = readSerializer(store.getChild(STORE_KEY_SERIALIZER_ELMT));
    if (keySerializer.getAllSchemaInfoVersions().size() > 1)
        throw new MappingException("Only a single schema is allowed for the store key.");
    SerializerDefinition valueSerializer = readSerializer(store.getChild(STORE_VALUE_SERIALIZER_ELMT));
    RoutingTier routingTier = RoutingTier.fromDisplay(store.getChildText(STORE_ROUTING_TIER_ELMT));
    String routingStrategyType = (null != store.getChildText(STORE_ROUTING_STRATEGY)) ? store.getChildText(STORE_ROUTING_STRATEGY) : RoutingStrategyType.CONSISTENT_STRATEGY;
    Element retention = store.getChild(STORE_RETENTION_POLICY_ELMT);
    Integer retentionPolicyDays = null;
    Integer retentionThrottleRate = null;
    Integer retentionFreqDays = null;
    if (retention != null) {
        int retentionDays = Integer.parseInt(retention.getText());
        if (retentionDays > 0) {
            retentionPolicyDays = retentionDays;
            Element throttleRate = store.getChild(STORE_RETENTION_SCAN_THROTTLE_RATE_ELMT);
            if (throttleRate != null)
                retentionThrottleRate = Integer.parseInt(throttleRate.getText());
            Element retentionFreqDaysElement = store.getChild(STORE_RETENTION_FREQ_ELMT);
            if (retentionFreqDaysElement != null)
                retentionFreqDays = Integer.parseInt(retentionFreqDaysElement.getText());
        } else {
            logger.error("Invalid retention policy days set. Should be greater than zero. ignoring value " + retentionDays);
        }
    }
    if (routingStrategyType.compareTo(RoutingStrategyType.ZONE_STRATEGY) == 0 && !SystemStoreConstants.isSystemStore(name)) {
        if (zoneCountReads == null || zoneCountWrites == null || zoneReplicationFactor == null) {
            throw new MappingException("Have not set one of the following correctly for store '" + name + "' - " + STORE_ZONE_COUNT_READS + ", " + STORE_ZONE_COUNT_WRITES + ", " + STORE_ZONE_REPLICATION_FACTOR_ELMT);
        }
    }
    HintedHandoffStrategyType hintedHandoffStrategy = null;
    if (store.getChildText(HINTED_HANDOFF_STRATEGY) != null)
        hintedHandoffStrategy = HintedHandoffStrategyType.fromDisplay(store.getChildText(HINTED_HANDOFF_STRATEGY));
    String hintPrefListSizeStr = store.getChildText(HINT_PREFLIST_SIZE);
    Integer hintPrefListSize = (null != hintPrefListSizeStr) ? Integer.parseInt(hintPrefListSizeStr) : null;
    String memoryFootprintStr = store.getChildText(STORE_MEMORY_FOOTPRINT);
    long memoryFootprintMB = 0;
    if (memoryFootprintStr != null)
        memoryFootprintMB = Long.parseLong(memoryFootprintStr);
    return new StoreDefinitionBuilder().setName(name).setType(storeType).setDescription(description).setOwners(owners).setKeySerializer(keySerializer).setValueSerializer(valueSerializer).setRoutingPolicy(routingTier).setRoutingStrategyType(routingStrategyType).setReplicationFactor(replicationFactor).setPreferredReads(preferredReads).setRequiredReads(requiredReads).setPreferredWrites(preferredWrites).setRequiredWrites(requiredWrites).setRetentionPeriodDays(retentionPolicyDays).setRetentionScanThrottleRate(retentionThrottleRate).setRetentionFrequencyDays(retentionFreqDays).setZoneReplicationFactor(zoneReplicationFactor).setZoneCountReads(zoneCountReads).setZoneCountWrites(zoneCountWrites).setHintedHandoffStrategy(hintedHandoffStrategy).setHintPrefListSize(hintPrefListSize).setMemoryFootprintMB(memoryFootprintMB).build();
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Element(org.jdom.Element) HintedHandoffStrategyType(voldemort.store.slop.strategy.HintedHandoffStrategyType) RoutingTier(voldemort.client.RoutingTier) ArrayList(java.util.ArrayList) List(java.util.List) SerializerDefinition(voldemort.serialization.SerializerDefinition)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Element (org.jdom.Element)1 RoutingTier (voldemort.client.RoutingTier)1 SerializerDefinition (voldemort.serialization.SerializerDefinition)1 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)1 HintedHandoffStrategyType (voldemort.store.slop.strategy.HintedHandoffStrategyType)1