本文整理汇总了Golang中github.com/balzaczyy/golucene/core/store.Directory.MakeLock方法的典型用法代码示例。如果您正苦于以下问题:Golang Directory.MakeLock方法的具体用法?Golang Directory.MakeLock怎么用?Golang Directory.MakeLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/balzaczyy/golucene/core/store.Directory
的用法示例。
在下文中一共展示了Directory.MakeLock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewIndexWriter
/*
Constructs a new IndexWriter per the settings given in conf. If you want to
make "live" changes to this writer instance, use Config().
NOTE: after this writer is created, the given configuration instance cannot be
passed to another writer. If you intend to do so, you should clone it
beforehand.
*/
func NewIndexWriter(d store.Directory, conf *IndexWriterConfig) (w *IndexWriter, err error) {
ans := &IndexWriter{
Locker: &sync.Mutex{},
ClosingControl: newClosingControl(),
segmentsToMerge: make(map[*SegmentInfoPerCommit]bool),
mergeExceptions: make([]*OneMerge, 0),
doAfterFlush: func() error { return nil },
doBeforeFlush: func() error { return nil },
commitLock: &sync.Mutex{},
fullFlushLock: &sync.Mutex{},
config: newLiveIndexWriterConfigFrom(conf),
directory: d,
analyzer: conf.analyzer,
infoStream: conf.infoStream,
mergePolicy: conf.mergePolicy,
mergeScheduler: conf.mergeScheduler,
codec: conf.codec,
bufferedDeletesStream: newBufferedDeletesStream(conf.infoStream),
poolReaders: conf.readerPooling,
writeLock: d.MakeLock(WRITE_LOCK_NAME),
}
ans.readerPool = newReaderPool(ans)
ans.MergeControl = newMergeControl(conf.infoStream, ans.readerPool)
conf.setIndexWriter(ans)
ans.mergePolicy.SetIndexWriter(ans)
// obtain write lock
if ok, err := ans.writeLock.ObtainWithin(conf.writeLockTimeout); !ok || err != nil {
if err != nil {
return nil, err
}
return nil, errors.New(fmt.Sprintf("Index locked for write: %v", ans.writeLock))
}
var success bool = false
defer func() {
if !success {
if ans.infoStream.IsEnabled("IW") {
ans.infoStream.Message("IW", "init: hit exception on init; releasing write lock")
}
ans.writeLock.Release() // don't mask the original exception
ans.writeLock = nil
}
}()
var create bool
switch conf.openMode {
case OPEN_MODE_CREATE:
create = true
case OPEN_MODE_APPEND:
create = false
default:
// CREATE_OR_APPEND - create only if an index does not exist
ok, err := IsIndexExists(d)
if err != nil {
return nil, err
}
create = !ok
}
// If index is too old, reading the segments will return
// IndexFormatTooOldError
ans.segmentInfos = &SegmentInfos{}
var initialIndexExists bool = true
if create {
// Try to read first. This is to allow create against an index
// that's currently open for searching. In this case we write the
// next segments_N file with no segments:
err = ans.segmentInfos.ReadAll(d)
if err == nil {
ans.segmentInfos.Clear()
} else {
// Likely this means it's a fresh directory
initialIndexExists = false
err = nil
}
// Record that we have a change (zero out all segments) pending:
ans.changed()
} else {
err = ans.segmentInfos.ReadAll(d)
if err != nil {
return
}
//.........这里部分代码省略.........