Skip to content

Commit ca102b0

Browse files
author
Alan Wright
committed
Fix for copy of compound file >2Go.
Alain Barbet <[email protected]>
1 parent cb36d1d commit ca102b0

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/core/index/CompoundFileWriter.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,60 +27,60 @@ namespace Lucene
2727
entries = Collection<FileEntry>::newInstance();
2828
merged = false;
2929
}
30-
30+
3131
CompoundFileWriter::~CompoundFileWriter()
3232
{
3333
}
34-
34+
3535
DirectoryPtr CompoundFileWriter::getDirectory()
3636
{
3737
return DirectoryPtr(_directory);
3838
}
39-
39+
4040
String CompoundFileWriter::getName()
4141
{
4242
return fileName;
4343
}
44-
44+
4545
void CompoundFileWriter::addFile(const String& file)
4646
{
4747
if (merged)
4848
boost::throw_exception(IllegalStateException(L"Can't add extensions after merge has been called"));
49-
49+
5050
if (file.empty())
5151
boost::throw_exception(IllegalArgumentException(L"file cannot be empty"));
52-
52+
5353
if (!ids.add(file))
5454
boost::throw_exception(IllegalArgumentException(L"File " + file + L" already added"));
55-
55+
5656
FileEntry entry;
5757
entry.file = file;
5858
entries.add(entry);
5959
}
60-
60+
6161
void CompoundFileWriter::close()
6262
{
6363
if (merged)
6464
boost::throw_exception(IllegalStateException(L"Merge already performed"));
65-
65+
6666
if (entries.empty())
6767
boost::throw_exception(IllegalStateException(L"No entries to merge have been defined"));
68-
68+
6969
merged = true;
70-
70+
7171
DirectoryPtr directory(_directory);
72-
72+
7373
// open the compound stream
7474
IndexOutputPtr os;
7575
LuceneException finally;
7676
try
7777
{
7878
os = directory->createOutput(fileName);
79-
79+
8080
// Write the number of entries
8181
os->writeVInt(entries.size());
82-
83-
// Write the directory with all offsets at 0. Remember the positions of directory entries so that we
82+
83+
// Write the directory with all offsets at 0. Remember the positions of directory entries so that we
8484
// can adjust the offsets later
8585
int64_t totalSize = 0;
8686
for (Collection<FileEntry>::iterator fe = entries.begin(); fe != entries.end(); ++fe)
@@ -90,31 +90,31 @@ namespace Lucene
9090
os->writeString(fe->file);
9191
totalSize += directory->fileLength(fe->file);
9292
}
93-
94-
// Pre-allocate size of file as optimization - this can potentially help IO performance as we write the
95-
// file and also later during searching. It also uncovers a disk-full situation earlier and hopefully
93+
94+
// Pre-allocate size of file as optimization - this can potentially help IO performance as we write the
95+
// file and also later during searching. It also uncovers a disk-full situation earlier and hopefully
9696
// without actually filling disk to 100%
9797
int64_t finalLength = totalSize + os->getFilePointer();
9898
os->setLength(finalLength);
99-
99+
100100
// Open the files and copy their data into the stream. Remember the locations of each file's data section.
101101
ByteArray buffer(ByteArray::newInstance(16384));
102102
for (Collection<FileEntry>::iterator fe = entries.begin(); fe != entries.end(); ++fe)
103103
{
104104
fe->dataOffset = os->getFilePointer();
105105
copyFile(*fe, os, buffer);
106106
}
107-
107+
108108
// Write the data offsets into the directory of the compound stream
109109
for (Collection<FileEntry>::iterator fe = entries.begin(); fe != entries.end(); ++fe)
110110
{
111111
os->seek(fe->directoryOffset);
112112
os->writeLong(fe->dataOffset);
113113
}
114-
114+
115115
BOOST_ASSERT(finalLength == os->length());
116-
117-
// Close the output stream. Set the os to null before trying to close so that if an exception occurs during
116+
117+
// Close the output stream. Set the os to null before trying to close so that if an exception occurs during
118118
// the close, the finally clause below will not attempt to close the stream the second time.
119119
IndexOutputPtr tmp(os);
120120
os.reset();
@@ -124,10 +124,10 @@ namespace Lucene
124124
{
125125
finally = e;
126126
}
127-
127+
128128
if (os)
129129
{
130-
try
130+
try
131131
{
132132
os->close();
133133
}
@@ -137,7 +137,7 @@ namespace Lucene
137137
}
138138
finally.throwException();
139139
}
140-
140+
141141
void CompoundFileWriter::copyFile(const FileEntry& source, IndexOutputPtr os, ByteArray buffer)
142142
{
143143
IndexInputPtr is;
@@ -146,15 +146,15 @@ namespace Lucene
146146
try
147147
{
148148
int64_t startPtr = os->getFilePointer();
149-
149+
150150
is = directory->openInput(source.file);
151151
int64_t length = is->length();
152152
int64_t remainder = length;
153-
int32_t chunk = buffer.size();
154-
153+
int64_t chunk = buffer.size();
154+
155155
while (remainder > 0)
156156
{
157-
int32_t len = std::min(chunk, (int32_t)remainder);
157+
int32_t len = (int32_t)std::min(chunk, remainder);
158158
is->readBytes(buffer.get(), 0, len, false);
159159
os->writeBytes(buffer.get(), len);
160160
remainder -= len;
@@ -164,15 +164,15 @@ namespace Lucene
164164
checkAbort->work(80);
165165
}
166166
}
167-
167+
168168
// Verify that remainder is 0
169169
if (remainder != 0)
170170
{
171-
boost::throw_exception(IOException(L"Non-zero remainder length after copying: " + StringUtils::toString(remainder) +
171+
boost::throw_exception(IOException(L"Non-zero remainder length after copying: " + StringUtils::toString(remainder) +
172172
L" (id: " + source.file + L", length: " + StringUtils::toString(length) +
173173
L", buffer size: " + StringUtils::toString(chunk) + L")"));
174174
}
175-
175+
176176
// Verify that the output length diff is equal to original file
177177
int64_t endPtr = os->getFilePointer();
178178
int64_t diff = endPtr - startPtr;
@@ -186,7 +186,7 @@ namespace Lucene
186186
{
187187
finally = e;
188188
}
189-
189+
190190
if (is)
191191
is->close();
192192
finally.throwException();

0 commit comments

Comments
 (0)