[ 
https://issues.apache.org/jira/browse/CASSANDRA-7622?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nate McCall updated CASSANDRA-7622:
-----------------------------------
    Comment: was deleted

(was: Github user zznate commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/205#discussion_r173964748
  
    --- Diff: src/java/org/apache/cassandra/db/virtual/Settings.java ---
    @@ -0,0 +1,161 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.cassandra.db.virtual;
    +
    +import java.lang.reflect.Array;
    +import java.lang.reflect.Field;
    +import java.lang.reflect.Modifier;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.function.Consumer;
    +
    +import org.apache.cassandra.config.Config;
    +import org.apache.cassandra.config.DatabaseDescriptor;
    +import org.apache.cassandra.cql3.CQL3Type;
    +import org.apache.cassandra.cql3.ColumnIdentifier;
    +import org.apache.cassandra.cql3.QueryOptions;
    +import org.apache.cassandra.cql3.restrictions.StatementRestrictions;
    +import org.apache.cassandra.db.DecoratedKey;
    +import org.apache.cassandra.db.InMemoryVirtualTable;
    +import org.apache.cassandra.db.rows.Row;
    +import org.apache.cassandra.exceptions.CassandraException;
    +import org.apache.cassandra.exceptions.InvalidRequestException;
    +import org.apache.cassandra.schema.ColumnMetadata;
    +import org.apache.cassandra.schema.TableMetadata;
    +import org.apache.cassandra.service.StorageProxy;
    +import org.apache.cassandra.service.StorageService;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.google.common.collect.ImmutableMap;
    +
    +public class Settings extends InMemoryVirtualTable
    +{
    +    private static final Logger logger = 
LoggerFactory.getLogger(Settings.class);
    +    private static Map<String, Consumer<String>> WRITABLES = 
ImmutableMap.<String, Consumer<String>>builder()
    +      .put("batch_size_warn_threshold_in_kb", v -> 
DatabaseDescriptor.setBatchSizeWarnThresholdInKB(Integer.parseInt(v)))
    +      .put("batch_size_fail_threshold_in_kb", v -> 
DatabaseDescriptor.setBatchSizeFailThresholdInKB(Integer.parseInt(v)))
    +
    +      .put("compaction_throughput_mb_per_sec", v -> 
StorageService.instance.setCompactionThroughputMbPerSec(Integer.parseInt(v)))
    +      .put("concurrent_compactors", v -> 
StorageService.instance.setConcurrentCompactors(Integer.parseInt(v)))
    +      .put("concurrent_validations", v -> 
StorageService.instance.setConcurrentValidators(Integer.parseInt(v)))
    +
    +      .put("tombstone_warn_threshold", v -> 
DatabaseDescriptor.setTombstoneWarnThreshold(Integer.parseInt(v)))
    +      .put("tombstone_failure_threshold", v -> 
DatabaseDescriptor.setTombstoneFailureThreshold(Integer.parseInt(v)))
    +
    +      .put("hinted_handoff_enabled", v -> 
StorageProxy.instance.setHintedHandoffEnabled(Boolean.parseBoolean(v)))
    +      .put("hinted_handoff_throttle_in_kb", v -> 
StorageService.instance.setHintedHandoffThrottleInKB(Integer.parseInt(v)))
    +
    +      .put("incremental_backups", v -> 
DatabaseDescriptor.setIncrementalBackupsEnabled(Boolean.parseBoolean(v)))
    +
    +      .put("inter_dc_stream_throughput_outbound_megabits_per_sec", v -> 
StorageService.instance.setInterDCStreamThroughputMbPerSec(Integer.parseInt(v)))
    +      .put("stream_throughput_outbound_megabits_per_sec", v -> 
StorageService.instance.setStreamThroughputMbPerSec(Integer.parseInt(v)))
    +
    +      .put("truncate_request_timeout_in_ms", v -> 
StorageService.instance.setTruncateRpcTimeout(Long.parseLong(v)))
    +      .put("cas_contention_timeout_in_ms", v -> 
StorageService.instance.setCasContentionTimeout(Long.parseLong(v)))
    +      .put("counter_write_request_timeout_in_ms", v -> 
StorageService.instance.setCounterWriteRpcTimeout(Long.parseLong(v)))
    +      .put("write_request_timeout_in_ms", v -> 
StorageService.instance.setWriteRpcTimeout(Long.parseLong(v)))
    +      .put("range_request_timeout_in_ms", v -> 
StorageService.instance.setRangeRpcTimeout(Long.parseLong(v)))
    +      .put("read_request_timeout_in_ms", v -> 
StorageService.instance.setReadRpcTimeout(Long.parseLong(v)))
    +      .put("request_timeout_in_ms",v -> 
StorageService.instance.setRpcTimeout(Long.parseLong(v)))
    +
    +      .put("phi_convict_threshold", v -> 
DatabaseDescriptor.setPhiConvictThreshold(Double.parseDouble(v)))
    +      .build();
    +
    +    public static Map<String, CQL3Type> columns()
    +    {
    +        Map<String, CQL3Type> definitions = new HashMap<>();
    +        definitions.put("setting", CQL3Type.Native.TEXT);
    +        definitions.put("value", CQL3Type.Native.TEXT);
    +        definitions.put("writable", CQL3Type.Native.BOOLEAN);
    +        return definitions;
    +    }
    +
    +    public static Key primaryKey()
    +    {
    +        return createKey().addKey("setting");
    +    }
    +
    +    ColumnMetadata valueColumn;
    +    public Settings(TableMetadata metadata)
    +    {
    +        super(metadata);
    +        valueColumn = 
metadata.getColumn(ColumnIdentifier.getInterned("value", false));
    +    }
    +
    +    public boolean writable()
    +    {
    +        return true;
    +    }
    +
    +    /**
    +     * Execute an update operation.
    +     *
    +     * @param partitionKey partition key for the update.
    +     * @param params parameters of the update.
    +     */
    +    @Override
    +    public void mutate(DecoratedKey partitionKey, Row row) throws 
CassandraException
    +    {
    +        String setting = 
metadata.partitionKeyType.getString(partitionKey.getKey());
    +        if (WRITABLES.get(setting) == null)
    +            throw new InvalidRequestException(setting + " is not a 
writable setting.");
    +        if (row.getCell(valueColumn) == null)
    +            throw new InvalidRequestException("Only 'value' is 
updatable.");
    +
    +        String value = 
valueColumn.type.getString(row.getCell(valueColumn).value());
    +        WRITABLES.get(setting).accept(value);
    +    }
    +
    +    public void read(StatementRestrictions restrictions, QueryOptions 
options, ResultBuilder result)
    +    {
    +        Field[] fields = Config.class.getFields();
    +        Config config = DatabaseDescriptor.getRawConfig();
    +        for (Field f : fields)
    +        {
    +            if (!Modifier.isStatic(f.getModifiers()))
    +            {
    +                try
    +                {
    +                    Object value = f.get(config);
    +                    if (value != null && value.getClass().isArray())
    +                    {
    +                        String s = "[";
    --- End diff --
    
    Dude, `StringBuilder`!!
)

> Implement virtual tables
> ------------------------
>
>                 Key: CASSANDRA-7622
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-7622
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Tupshin Harper
>            Assignee: Chris Lohfink
>            Priority: Major
>             Fix For: 4.x
>
>
> There are a variety of reasons to want virtual tables, which would be any 
> table that would be backed by an API, rather than data explicitly managed and 
> stored as sstables.
> One possible use case would be to expose JMX data through CQL as a 
> resurrection of CASSANDRA-3527.
> Another is a more general framework to implement the ability to expose yaml 
> configuration information. So it would be an alternate approach to 
> CASSANDRA-7370.
> A possible implementation would be in terms of CASSANDRA-7443, but I am not 
> presupposing.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to