MojErr MojDbQuery::WhereClause::setUpper(CompOp op, const MojObject& val, MojDbCollationStrength coll) { if (m_upperOp != OpNone) MojErrThrow(MojErrDbInvalidQueryOpCombo); MojErr err = collation(coll); MojErrCheck(err); m_upperOp = op; m_upperVal = val; return MojErrNone; }
static Vector<String> sortLocaleData(const String& locale, const String& key) { // 9.1 Internal slots of Service Constructors & 10.2.3 Internal slots (ECMA-402 2.0) Vector<String> keyLocaleData; if (key == "co") { // 10.2.3 "The first element of [[sortLocaleData]][locale].co and [[searchLocaleData]][locale].co must be null for all locale values." keyLocaleData.append(String()); UErrorCode status = U_ZERO_ERROR; UEnumeration* enumeration = ucol_getKeywordValuesForLocale("collation", locale.utf8().data(), TRUE, &status); if (U_SUCCESS(status)) { const char* keywordValue; while ((keywordValue = uenum_next(enumeration, nullptr, &status)) && U_SUCCESS(status)) { String collation(keywordValue); // 10.2.3 "The values "standard" and "search" must not be used as elements in any [[sortLocaleData]][locale].co and [[searchLocaleData]][locale].co array." if (collation == "standard" || collation == "search") continue; // Map keyword values to BCP 47 equivalents. if (collation == "dictionary") collation = ASCIILiteral("dict"); else if (collation == "gb2312han") collation = ASCIILiteral("gb2312"); else if (collation == "phonebook") collation = ASCIILiteral("phonebk"); else if (collation == "traditional") collation = ASCIILiteral("trad"); keyLocaleData.append(collation); } uenum_close(enumeration); } } else if (key == "kn") { keyLocaleData.append(ASCIILiteral("false")); keyLocaleData.append(ASCIILiteral("true")); } else ASSERT_NOT_REACHED(); return keyLocaleData; }
void StatCounter::record(time_t time, double value, double valueSq, double min, double max, size_t cnt) { if(debugRecord.enabled()) { LogDebug << "record" << value << valueSq << min << max << cnt << time; } else { LogSpam << "StatCounter::record thread_id " << boost::this_thread::get_id(); } ++dequeueRecords_; --queueLenRecords_; time_t nowTime; if(isCollated_) { if(time > istat::istattime(&nowTime) + collationInterval_) { ++recordsFromTheFuture_; if (debugRejectedCounters) { LogWarning << "StatCounter::record rejected counter from the future: " << time << " > " << nowTime << ": " << counters_[0].file->header().name; } return; } if(time < collations_[0].time) { ++recordsFromThePast_; if (debugRejectedCounters) { LogWarning << "StatCounter::record rejected counter from the past: " << time << " < " << collations_[0].time << " < " << collations_[1].time << " < " << collations_[2].time << ": " << counters_[0].file->header().name; } return; } } else { if(time > istat::istattime(&nowTime) + time_t(60)) { if (debugRejectedCounters) { LogWarning << "StatCounter::record rejected counter from the future: " << time << " > " << nowTime << ": " << counters_[0].file->header().name; } ++recordsFromTheFuture_; return; } } if(isCollated_) { time -= time % collationInterval_; size_t i = findCollationIndex(time); // No matching bucket candidate in time range. Shift ahead! if(i == BUCKETS_PER_COLLATION_WINDOW) { if(collations_[0].time == 0) { for(size_t i = 0; i != BUCKETS_PER_COLLATION_WINDOW; ++i) { collations_[(BUCKETS_PER_COLLATION_WINDOW - 1) - i] = CollationInfo(time - (i * collationInterval_)); } } else { maybeShiftCollated(time); } i = findCollationIndex(time); } CollationInfo &collation(collations_[i]); istat::Bucket &bucket(collation.bucket); bucket.collatedUpdate(value / double(collationInterval_), time); ++collation.writes; // Only update the statfile on power-of-two updates. if((collation.writes & (collation.writes - 1)) == 0) { counters_.begin()->file->updateBucket(bucket); } } else { // Don't record zero-sample buckets. if(cnt == 0) { ++recordsRejected_; if (debugRejectedCounters) { LogWarning << "StatCounter::record rejected counter with 0 count: " << counters_[0].file->header().name; } return; } double avg = value / double(cnt); // Ensure the value ranges are sensible, or reject them. // We allow a small amount of epsilon (0.01%) here before rejecting counters due to double vs. float // conversion in Buckets transferred from istatd agents to the master if (min > (max + fabs(max) * 0.0001) || (avg + fabs(avg) * 0.0001) < min || avg > (max + fabs(max) * 0.0001)) { if (debugRejectedCounters) { LogWarning << "StatCounter::record rejected counter with bad min/avg/max: " << counters_[0].file->header().name << min << avg << "(" << value << "/" << cnt << ")" << max; } ++recordsRejected_; return; } istat::Bucket b(value, float(valueSq), float(min), float(max), int(cnt), time); for(std::vector<OneCounter>::iterator ptr(counters_.begin()), end(counters_.end()); ptr != end; ++ptr) { ptr->file->updateBucket(b); } } }