我遇到了我的MongoDB Java驅動程序3.0版的問題。在對幾個集合(updateOne,find)執行幾個操作之後,我得到一個Command failed with error 8: '24: Too many open files'
錯誤。我在我的代碼oftenly執行的典型操作是下列之一:MongoDB Java API 3.0關閉遊標
private Document findFirst(int i) {
FindIterable<Document> cursor = collection.find(new Document("_id", i)).limit(1);
Document exists = null;
for (Document doc : cursor) {
exists = doc;
break;
}
return exists;
}
Document exists = findFirst(integer);
return exists != null ? new MongoDBDocument(collection,exists) : null;
,當我查找了的ID,「會話」未關閉:
Set<Integer> s = new HashSet<>();
for (Document k : collection.find().projection(new Document("_id",1))) { //Fully scan the collection
s.add(Integer.valueOf((String)k.get("_id")));
}
return s;
於是,我看到了在老版API中,查找操作的結果返回了必須關閉的DBCursor。在我看來,在當前的實現中,沒有光標被關閉。我看到要實現這個功能的唯一方法是每次關閉MongoClient,但最有可能的是我沒有以正確的方式完成任何事情。也許,當我用db.getCollection(name)
檢索集合時,必須在對它進行一些操作後以某種方式關閉它:我嘗試閱讀文檔,但沒有任何幫助。
服務器的日誌返回詳細的錯誤是以下之一:
2016-04-24T13:20:32.839+0200 E STORAGE [conn721] WiredTiger (24) [1461496832:839907][968:0x700000934000], WT_SESSION.create: /data/db/index-1232-7182838846905439482.wt: Too many open files
2016-04-24T13:20:32.840+0200 I COMMAND [conn721] command alledges.$cmd command: createIndexes { createIndexes: "2071853587", indexes: [ { key: { _id: 2071853587 }, name: "_id_2071853587", ns: "alledges.2071853587" } ] } keyUpdates:0 writeConflicts:0 exception: 24: Too many open files code:8 numYields:0 reslen:83 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } } } protocol:op_query 539ms
我在哪裏錯了?提前致謝。