示例#1
0
        internal IndexOutput CreateOutput(string name, IOContext context)
        {
            EnsureOpen();
            bool success      = false;
            bool outputLocked = false;

            try
            {
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(name != null, "name must not be null");
                }
                if (entries.ContainsKey(name))
                {
                    throw new ArgumentException("File " + name + " already exists");
                }
                FileEntry entry = new FileEntry();
                entry.File    = name;
                entries[name] = entry;
                string id = IndexFileNames.StripSegmentName(name);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(!seenIDs.Contains(id), () => "file=\"" + name + "\" maps to id=\"" + id + "\", which was already written");
                }
                seenIDs.Add(id);
                DirectCFSIndexOutput @out;

                if ((outputLocked = outputTaken.CompareAndSet(false, true)))
                {
                    @out = new DirectCFSIndexOutput(this, GetOutput(), entry, false);
                }
                else
                {
                    entry.Dir = this.directory;
                    @out      = new DirectCFSIndexOutput(this, directory.CreateOutput(name, context), entry, true);
                }
                success = true;
                return(@out);
            }
            finally
            {
                if (!success)
                {
                    entries.Remove(name);
                    if (outputLocked) // release the output lock if not successful
                    {
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(outputTaken);
                        }
                        ReleaseOutputLock();
                    }
                }
            }
        }
示例#2
0
        internal IndexOutput CreateOutput(string name, IOContext context)
        {
            EnsureOpen();
            bool success = false;
            bool outputLocked = false;
            try
            {
                Debug.Assert(name != null, "name must not be null");
                if (Entries.ContainsKey(name))
                {
                    throw new System.ArgumentException("File " + name + " already exists");
                }
                FileEntry entry = new FileEntry();
                entry.File = name;
                Entries[name] = entry;
                string id = IndexFileNames.StripSegmentName(name);
                Debug.Assert(!SeenIDs.Contains(id), "file=\"" + name + "\" maps to id=\"" + id + "\", which was already written");
                SeenIDs.Add(id);
                DirectCFSIndexOutput @out;

                if ((outputLocked = OutputTaken.CompareAndSet(false, true)))
                {
                    @out = new DirectCFSIndexOutput(this, Output, entry, false);
                }
                else
                {
                    entry.Dir = this.Directory_Renamed;
                    @out = new DirectCFSIndexOutput(this, Directory_Renamed.CreateOutput(name, context), entry, true);
                }
                success = true;
                return @out;
            }
            finally
            {
                if (!success)
                {
                    Entries.Remove(name);
                    if (outputLocked) // release the output lock if not successful
                    {
                        Debug.Assert(OutputTaken.Get());
                        ReleaseOutputLock();
                    }
                }
            }
        }