// https://github.com/facebook/rocksdb/blob/master/include/rocksdb/c.h
// https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h
435965
func RocksOpts(options *Options) *rocks.Options {

	if options == nil {
		m := make(Options)
		options = &m
	}

	// ToDo
	env := rocks.NewDefaultEnv()

	if n, ok := options.IntKey("background_threads"); ok {
		env.SetBackgroundThreads(n)
		log.Printf("config env.SetBackgroundThreads(%d)\n", n)
	}

	if n, ok := options.IntKey("high_priority_background_threads"); ok {
		env.SetHighPriorityBackgroundThreads(n)
		log.Printf("config env.SetHighPriorityBackgroundThreads(%d)\n", n)
	}

	opts := rocks.NewOptions()
	opts.SetEnv(env)

	if b, ok := options.BoolKey("read_only"); ok {
		opts.SetReadOnly(b)
		log.Printf("config opts.SetReadOnly(%v)\n", b)
	}

	cacheSize := DefaultCacheSize
	if n, ok := options.IntKey("cache_size"); ok {
		cacheSize = n
	}
	cache := rocks.NewLRUCache(cacheSize)
	opts.SetCache(cache)

	// opts.SetComparator(cmp)
	opts.SetErrorIfExists(false)

	if n, ok := options.IntKey("increase_parallelism"); ok {
		opts.IncreaseParallelism(n)
		log.Printf("config opts.IncreaseParallelism(%d)\n", n)
	}

	if b, ok := options.BoolKey("disable_data_sync"); ok {
		opts.SetDisableDataSync(b)
		log.Printf("config opts.SetDisableDataSync(%v)\n", b)
	}

	if n, ok := options.IntKey("bytes_per_sync_power"); ok {
		opts.SetBytesPerSync(uint64(1) << uint64(n))
		log.Printf("config opts.SetBytesPerSync(%d)\n", uint64(1)<<uint64(n))
	}

	if n, ok := options.IntKey("log_level"); ok {
		opts.SetLogLevel(n)
		log.Printf("config opts.SetLogLevel(%d)\n", n)
	}

	if dir, ok := options.StringKey("log_dir"); ok {
		opts.SetLogDir(dir)
		log.Printf("config opts.SetLogDir(%s)\n", dir)
	}

	if dir, ok := options.StringKey("wal_dir"); ok {
		opts.SetLogDir(dir)
		log.Printf("config opts.SetWalDir(%s)\n", dir)
	}

	if n, ok := options.IntKey("stats_dump_period"); ok {
		opts.SetStatsDumpPeriod(uint(n))
		log.Printf("config opts.SetStatsDumpPeriod(%d)\n", n)
	}

	if n, ok := options.IntKey("write_buffer_size"); ok {
		opts.SetWriteBufferSize(n)
		log.Printf("config opts.SetWriteBufferSize(%d)\n", n)
	}

	if n, ok := options.IntKey("write_buffer_size_power"); ok {
		opts.SetWriteBufferSize(int(uint64(1) << uint64(n)))
		log.Printf("config opts.SetWriteBufferSize(%d)\n", int(uint64(1)<<uint(n)))
	}

	if b, ok := options.BoolKey("paranoid_checks"); ok {
		opts.SetParanoidChecks(b)
		log.Printf("config opts.SetParanoidChecks(%v)\n", b)
	}

	if b, ok := options.BoolKey("allow_mmap_reads"); ok {
		opts.SetAllowMMapReads(b)
		log.Printf("config opts.SetAllowMMapReads(%v)\n", b)
	}

	if b, ok := options.BoolKey("allow_mmap_writes"); ok {
		opts.SetAllowMMapWrites(b)
		log.Printf("config opts.SetAllowMMapWrites(%v)\n", b)
	}

	if b, ok := options.BoolKey("allow_os_buffer"); ok {
		opts.SetAllowOSBuffer(b)
		log.Printf("config opts.SetAllowOSBuffer(%v)\n", b)
	}

	if n, ok := options.IntKey("max_open_files"); ok {
		opts.SetMaxOpenFiles(n)
		log.Printf("config opts.SetMaxOpenFiles(%d)\n", n)
	}

	if n, ok := options.IntKey("max_write_buffer_number"); ok {
		opts.SetMaxWriteBufferNumber(n)
		log.Printf("config opts.SetMaxWriteBufferNumber(%d)\n", n)
	}

	if n, ok := options.IntKey("min_write_buffer_number_to_merge"); ok {
		opts.SetMinWriteBufferNumberToMerge(n)
		log.Printf("config opts.SetMinWriteBufferNumberToMerge(%d)\n", n)
	}

	// if n, ok := options.IntKey("block_size"); ok {
	// 	opts.SetBlockSize(n)
	// 	log.Printf("config opts.SetBlockSize(%d)\n", n)
	// }

	// if n, ok := options.IntKey("block_restart_interval"); ok {
	// 	opts.SetBlockRestartInterval(n)
	// 	log.Printf("config opts.SetBlockRestartInterval(%d)\n", n)
	// }

	// Compaction

	if n, ok := options.IntKey("num_levels"); ok {
		opts.SetNumLevels(n)
		log.Printf("config opts.SetNumLevels(%d)\n", n)
	}

	if n, ok := options.IntKey("level0_num_file_compaction_trigger"); ok {
		opts.SetLevel0FileNumCompactionTrigger(n)
		log.Printf("config opts.SetLevel0FileNumCompactionTrigger(%d)\n", n)
	}

	if n, ok := options.IntKey("target_file_size_base_power"); ok {
		opts.SetTargetFileSizeBase(uint64(1) << uint64(n))
		log.Printf("config opts.SetTargetFileSizeBase(%d)\n", uint64(1)<<uint64(n))
	}

	if n, ok := options.IntKey("target_file_size_multiplier"); ok {
		opts.SetTargetFileSizeMultiplier(n)
		log.Printf("config opts.SetTargetFileSizeMultiplier(%d)\n", n)
	}

	if n, ok := options.IntKey("max_background_compactions"); ok {
		opts.SetMaxBackgroundCompactions(n)
		log.Printf("config opts.SetMaxBackgroundCompactions(%d)\n", n)
	}

	if n, ok := options.IntKey("max_background_flushes"); ok {
		opts.SetMaxBackgroundFlushes(n)
		log.Printf("config opts.SetMaxBackgroundFlushes(%d)\n", n)
	}

	comp, ok := options.StringKey("compression")
	if !ok {
		opts.SetCompression(rocks.NoCompression)
	} else {
		// ToDo: https://github.com/facebook/rocksdb/blob/master/include/rocksdb/c.h#L520-L527
		switch comp {
		case "snappy":
			opts.SetCompression(rocks.SnappyCompression)
		case "none":
			opts.SetCompression(rocks.NoCompression)
		default:
			panic(fmt.Errorf("Bad compression: %s", comp))
			return nil
		}
	}

	opts.SetCreateIfMissing(true)
	opts.SetErrorIfExists(false)

	return opts
}
203947
func (m *Meta) backend_c_R_s(c *configs.Backend, sMgr *state.LocalState) (backend.Backend, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics

	m.Ui.Error(strings.TrimSpace(errBackendLegacy) + "\n")

	diags = diags.Append(fmt.Errorf("Cannot initialize legacy remote state"))
	return nil, diags
}
391746
func (section *Section) AddInclude(filename string) {
	section.includes = append(section.includes, filename)
}
1114262
func (api *DatabaseAPI) Include(key string) *DatabaseAPI {
	api.include(key)
	return api
}
1215955
func (t *Table) C(name string) NonAliasColumn {
	return &deferredLookupColumn{
		table:   t,
		colName: name,
	}
}
793750
func (db *Database) Options() Options {
	db.mux.Lock()
	defer db.mux.Unlock()
	return Options{
		Address:    db.address,
		Network:    db.network,
		Timeout:    db.timeout,
		Index:      db.index,
		Password:   db.password,
		PoolSize:   db.poolsize,
		Logging:    db.logging,
		Monitoring: db.monitoring,
	}
}
1119908
func (o Options) Sdump(values ...interface{}) string {
	buf := new(bytes.Buffer)
	for i, value := range values {
		if i > 0 {
			buf.Write([]byte(o.Separator))
		}
		state := newDumpState(value, &o, buf)
		state.dump(value)
	}
	return buf.String()
}
815184
func (opts *TransactionOptions) Destroy() {
	C.rocksdb_transaction_options_destroy(opts.c)
	opts.c = nil
}
841588
func CreateDB(conf *Conf) *DB {
	readOpts := &opt.ReadOptions{}
	writeOptsNoSync := &opt.WriteOptions{}
	writeOptsSync := &opt.WriteOptions{}
	writeOptsSync.Sync = true

	return &DB{
		conf:            conf,
		dbState:         closed,
		readOpts:        readOpts,
		writeOptsNoSync: writeOptsNoSync,
		writeOptsSync:   writeOptsSync}
}
500423
func (p *parser) pushOptions() {
	p.optionsStack = append(p.optionsStack, p.options)
}
505600
func (opts *Options) SetHardRateLimit(value float64) {
	C.rocksdb_options_set_hard_rate_limit(opts.c, C.double(value))
}
179578
func (opts *BlockBasedTableOptions) Destroy() {
	C.rocksdb_block_based_options_destroy(opts.c)
	opts.c = nil
	opts.cache = nil
	opts.compCache = nil
}
1061099
func (opts *Options) SetIsFdCloseOnExec(value bool) {
	C.rocksdb_options_set_is_fd_close_on_exec(opts.c, boolToChar(value))
}
1179472
func (d *Databases) AllDB(ctx context.Context) ([]chronograf.Database, error) {
	return d.AllDBF(ctx)
}
102057
func (F *Frisby) Options(url string) *Frisby {
	F.Method = "OPTIONS"
	F.Url = url
	return F
}
126299
func (f *sendReceiveFolder) dbUpdaterRoutine(dbUpdateChan <-chan dbUpdateJob) {
	const maxBatchTime = 2 * time.Second

	batch := newFileInfoBatch(nil)
	tick := time.NewTicker(maxBatchTime)
	defer tick.Stop()

	changedDirs := make(map[string]struct{})
	found := false
	var lastFile protocol.FileInfo

	batch.flushFn = func(files []protocol.FileInfo) error {
		// sync directories
		for dir := range changedDirs {
			delete(changedDirs, dir)
			fd, err := f.fs.Open(dir)
			if err != nil {
				l.Debugf("fsync %q failed: %v", dir, err)
				continue
			}
			if err := fd.Sync(); err != nil {
				l.Debugf("fsync %q failed: %v", dir, err)
			}
			fd.Close()
		}

		// All updates to file/folder objects that originated remotely
		// (across the network) use this call to updateLocals
		f.updateLocalsFromPulling(files)

		if found {
			f.ReceivedFile(lastFile.Name, lastFile.IsDeleted())
			found = false
		}

		return nil
	}

loop:
	for {
		select {
		case job, ok := <-dbUpdateChan:
			if !ok {
				break loop
			}

			switch job.jobType {
			case dbUpdateHandleFile, dbUpdateShortcutFile:
				changedDirs[filepath.Dir(job.file.Name)] = struct{}{}
			case dbUpdateHandleDir:
				changedDirs[job.file.Name] = struct{}{}
			case dbUpdateHandleSymlink, dbUpdateInvalidate:
				// fsyncing symlinks is only supported by MacOS
				// and invalidated files are db only changes -> no sync
			}

			// For some reason we seem to care about file deletions and
			// content modification, but not about metadata and dirs/symlinks.
			if !job.file.IsInvalid() && job.jobType&(dbUpdateHandleFile|dbUpdateDeleteFile) != 0 {
				found = true
				lastFile = job.file
			}

			job.file.Sequence = 0

			batch.append(job.file)

			batch.flushIfFull()

		case <-tick.C:
			batch.flush()
		}
	}

	batch.flush()
}
1153575
func includeCallback(name, filename, namespace *C.char, userData unsafe.Pointer) *C.char {
	callbackFunc := callbackData.Get(userData).(CompilerIncludeFunc)
	if buf := callbackFunc(
		C.GoString(name), C.GoString(filename), C.GoString(namespace),
	); buf != nil {
		ptr := C.calloc(1, C.size_t(len(buf)+1))
		if ptr == nil {
			return nil
		}
		outbuf := make([]byte, 0)
		hdr := (*reflect.SliceHeader)(unsafe.Pointer(&outbuf))
		hdr.Data, hdr.Len = uintptr(ptr), len(buf)+1
		copy(outbuf, buf)
		return (*C.char)(ptr)
	}
	return nil
}