コード例 #1
0
 protected <T> Future<List<FDBMetric.Value<T>>> readAllValues(
     Transaction tr, final BaseMetricImpl<T> metric) {
   tr.options().setAccessSystemKeys();
   return tr.getRange(
           dataSubspace.pack(
               tupleFrom(metric.getType(), metric.getName(), address, DEFAULT_ID, 0)),
           dataSubspace.pack(
               tupleFrom(metric.getType(), metric.getName(), address, DEFAULT_ID, NLEVELS)))
       .asList()
       .map(
           new Function<List<KeyValue>, List<FDBMetric.Value<T>>>() {
             @Override
             public List<FDBMetric.Value<T>> apply(List<KeyValue> kvs) {
               List<FDBMetric.Value<T>> result = new ArrayList<>();
               for (KeyValue kv : kvs) {
                 result.addAll(metric.decodeValues(kv.getValue()));
               }
               // Merge all levels.
               Collections.sort(
                   result,
                   new Comparator<FDBMetric.Value<T>>() {
                     @Override
                     public int compare(FDBMetric.Value<T> v1, FDBMetric.Value<T> v2) {
                       if (v1.time < v2.time) return -1;
                       else if (v1.time > v2.time) return +1;
                       else return 0;
                     }
                   });
               return result;
             }
           });
 }
コード例 #2
0
 public void deleteLongMetric(Transaction tr, String name) {
   tr.clear(Range.startsWith(dataSubspace.pack(tupleFrom(LONG_TYPE, name))));
   tr.clear(Range.startsWith(confSubspace.pack(tupleFrom(LONG_TYPE, name))));
 }
コード例 #3
0
 protected void writeMetrics() {
   boolean anyConfChanges = false;
   for (BaseMetricImpl<?> metric : metrics.values()) {
     if (!metric.confChanged && !metric.valueChanged) continue;
     synchronized (metric) {
       if (metric.confChanged) {
         anyConfChanges = true;
         pendingWrites.add(
             new KeyValue(
                 confSubspace.pack(
                     tupleFrom(
                         metric.getType(), metric.getName(), address, DEFAULT_ID, ENABLED_OPTION)),
                 metric.enabled ? ENABLED_TRUE : ENABLED_FALSE));
         metric.confChanged = false;
       }
       if (metric.valueChanged) {
         pendingWrites.add(
             new KeyValue(
                 dataSubspace.pack(
                     tupleFrom(metric.getType(), metric.getName(), address, DEFAULT_ID)),
                 metric.encodeValue()));
         metric.valueChanged = false;
       }
       for (int level = 0; level < NLEVELS; level++) {
         MetricLevel<?> metricLevel = metric.levels.get(level);
         while (true) {
           MetricLevelValues values = metricLevel.values.pollFirst();
           if (values == null) break;
           pendingWrites.add(
               new KeyValue(
                   dataSubspace.pack(
                       tupleFrom(
                           metric.getType(),
                           metric.getName(),
                           address,
                           DEFAULT_ID,
                           level,
                           values.start)),
                   values.bytes));
           // Continue to fill (will overwrite key with longer value).
           if (metricLevel.values.isEmpty() && !values.isFull()) {
             metricLevel.values.addLast(values);
             break;
           }
         }
       }
     }
   }
   if (anyConfChanges) {
     // Signal a change in configuration. We will respond to this change,
     // too, but that seemd harmless and difficult to avoid in a general
     // way.
     byte[] bytes = new byte[16];
     random.nextBytes(bytes);
     if (logger.isDebugEnabled()) {
       logger.debug("Writing {}: {}", METRIC_CONF_CHANGES_KEY, ByteArrayUtil.printable(bytes));
     }
     pendingWrites.add(new KeyValue(confChangesSubspace.getKey(), bytes));
   }
   if (!pendingWrites.isEmpty()) {
     getDatabase()
         .run(
             new Function<Transaction, Void>() {
               @Override
               public Void apply(Transaction tr) {
                 tr.options().setAccessSystemKeys();
                 for (KeyValue kv : pendingWrites) {
                   tr.set(kv.getKey(), kv.getValue());
                 }
                 return null;
               }
             });
     pendingWrites.clear();
   }
 }
コード例 #4
0
 public void deleteBooleanMetric(Transaction tr, String name) {
   tr.clear(Range.startsWith(dataSubspace.pack(tupleFrom(BOOLEAN_TYPE, name))));
   tr.clear(Range.startsWith(confSubspace.pack(tupleFrom(BOOLEAN_TYPE, name))));
 }