Skip to content

Commit 84c4698

Browse files
author
mengli
committed
Fix OutofMemory bug when memcached is down.
1 parent 48d7b23 commit 84c4698

File tree

2 files changed

+202
-181
lines changed

2 files changed

+202
-181
lines changed

build.xml

Lines changed: 201 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,201 @@
1-
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<!--
3-
Copyright (c) 2009 Schooner Information Technology, Inc.
4-
All rights reserved.
5-
6-
http://www.schoonerinfotech.com/
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions
10-
are met:
11-
1. Redistributions of source code must retain the above copyright
12-
notice, this list of conditions and the following disclaimer.
13-
2. Redistributions in binary form must reproduce the above copyright
14-
notice, this list of conditions and the following disclaimer in the
15-
documentation and/or other materials provided with the distribution.
16-
3. The name of the author may not be used to endorse or promote products
17-
derived from this software without specific prior written permission.
18-
19-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
-->
30-
<project name="Memcached-Java-Client" default="jar" basedir=".">
31-
<property file="build.properties" />
32-
<path id="emma.lib">
33-
<pathelement location="${emma.dir}/emma.jar" />
34-
<pathelement location="${emma.dir}/emma_ant.jar" />
35-
</path>
36-
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
37-
<path id="test.classpath">
38-
<pathelement location="${junit.jar}" />
39-
<pathelement location="${log4j.jar}" />
40-
</path>
41-
<target name="clean">
42-
<delete dir="${build.dir}" />
43-
<delete dir="${test.build.dir}" />
44-
</target>
45-
46-
<!-- compilation target for packeging operations -->
47-
<target name="compile" depends="clean">
48-
<mkdir dir="${build.dir}" />
49-
<mkdir dir="${test.build.dir}" />
50-
<javac optimize="yes" srcdir="${src.dir}" destdir="${build.dir}" deprecation="true" target="1.5" source="1.5" nowarn="true" />
51-
<javac optimize="yes" srcdir="${test.dir}" destdir="${test.build.dir}" deprecation="true" target="1.5" source="1.5" nowarn="true">
52-
<classpath refid="test.classpath" />
53-
<classpath path="${build.dir}" />
54-
</javac>
55-
</target>
56-
57-
<target name="jar">
58-
<antcall target="clean" />
59-
<antcall target="compile" />
60-
<jar jarfile="${project}_${ver}.jar">
61-
<fileset dir="${build.dir}">
62-
<include name="com/schooner/MemCached/**/*" />
63-
<include name="com/danga/MemCached/**/*" />
64-
</fileset>
65-
</jar>
66-
<jar jarfile="${project}_test_${ver}.jar">
67-
<fileset dir="${test.build.dir}">
68-
<include name="com/schooner/MemCached/**/*" />
69-
<include name="com/danga/MemCached/**/*" />
70-
</fileset>
71-
</jar>
72-
<antcall target="clean" />
73-
</target>
74-
75-
<target name="runTest" depends="compile">
76-
<emma enabled="${emma.enabled}">
77-
<instr instrpath="${build.dir}" metadatafile="${report.dir}/metadata.emma" mode="overwrite">
78-
<filter value="+com.schooner.MemCached.*, -com.schooner.MemCached.*Test*, -com.danga.MemCached.*" />
79-
</instr>
80-
</emma>
81-
<junit printsummary="yes" showoutput="true" fork="true">
82-
<classpath>
83-
<pathelement location="${build.dir}" />
84-
<pathelement location="${test.build.dir}" />
85-
<path refid="emma.lib" />
86-
<path refid="test.classpath" />
87-
</classpath>
88-
<jvmarg value="-Dmemcached.host=${memcached.host}" />
89-
<jvmarg value="-Demma.coverage.out.file=${report.dir}/coverage.emma" />
90-
<jvmarg value="-Demma.coverage.out.merge=true" />
91-
<formatter type="xml" />
92-
<test name="com.schooner.MemCached.MemCachedClientAsciiTest" todir="${report.dir}" />
93-
<!--Enable the binary protocol unit test by uncomment the following line.
94-
Memcached binary protocol is supported by memcached 1.4+.
95-
Make sure the server is ready before starting these tests.
96-
You can specify the memcached host in the build.properties file in the same folder.
97-
-->
98-
<test name="com.schooner.MemCached.MemCachedClientBinaryTest" todir="${report.dir}" />
99-
<test name="com.schooner.MemCached.MemcachedClientUDPTest" todir="${report.dir}" />
100-
<test name="com.schooner.MemCached.OtherTest" todir="${report.dir}" />
101-
<test name="com.schooner.MemCached.WhalinScenarioTest" todir="${report.dir}" />
102-
</junit>
103-
<junitreport todir="${report.dir}">
104-
<fileset dir="${report.dir}">
105-
<include name="TEST-*.xml" />
106-
</fileset>
107-
<report format="frames" todir="${report.dir}" />
108-
</junitreport>
109-
<emma enabled="${emma.enabled}">
110-
<report sourcepath="${src.dir}">
111-
<fileset dir="${report.dir}">
112-
<include name="*.emma" />
113-
</fileset>
114-
<txt outfile="${report.dir}/coverage.txt" />
115-
<html outfile="${report.dir}/coverage.html" />
116-
</report>
117-
</emma>
118-
</target>
119-
120-
<target name="checkJavadoc">
121-
<available file="javadoc" property="javadoc.present" />
122-
</target>
123-
124-
<target name="checkReport">
125-
<available file="${report.dir}" property="report.present" />
126-
</target>
127-
128-
<target name="removeJavadoc" depends="checkJavadoc" if="javadoc.present">
129-
<delete>
130-
<fileset dir="javadoc">
131-
<include name="*" />
132-
</fileset>
133-
</delete>
134-
</target>
135-
<target name="removeReport" depends="checkReport" if="report.present">
136-
<delete>
137-
<fileset dir="${report.dir}">
138-
<include name="*" />
139-
</fileset>
140-
</delete>
141-
</target>
142-
143-
<target name="all">
144-
<delete>
145-
<fileset dir=".">
146-
<include name="*.jar" />
147-
<include name="*.zip" />
148-
</fileset>
149-
</delete>
150-
<antcall target="removeJavadoc" />
151-
<antcall target="removeReport" />
152-
<antcall target="runTest" />
153-
<antcall target="jar" />
154-
<antcall target="sourceDist" />
155-
<antcall target="javadoc" />
156-
</target>
157-
<target name="sourceDist">
158-
<mkdir dir="${project}_${ver}" />
159-
<copy todir="${project}_${ver}">
160-
<fileset dir=".">
161-
<include name="src/**/*" />
162-
<include name="doc/**/*" />
163-
<include name="lib/**/*" />
164-
<include name="report/**/*" />
165-
<include name=".*" />
166-
<include name="*.xml" />
167-
<include name="*.properties" />
168-
<include name="*.cld" />
169-
</fileset>
170-
</copy>
171-
<zip destfile="${project}_src_${ver}.zip" basedir=".">
172-
<include name="${project}_${ver}/**/*" />
173-
</zip>
174-
<delete dir="${project}_${ver}" />
175-
</target>
176-
<target name="javadoc">
177-
<javadoc access="public" author="true" classpath="lib/junit.jar" destdir="javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="com.schooner.MemCached,com.schooner.MemCached.command,com.danga.MemCached" source="1.5" sourcepath="src/main" splitindex="true" use="true" version="true" />
178-
</target>
179-
</project>
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<!--
3+
Copyright (c) 2009 Schooner Information Technology, Inc.
4+
All rights reserved.
5+
6+
http://www.schoonerinfotech.com/
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions
10+
are met:
11+
1. Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
2. Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
3. The name of the author may not be used to endorse or promote products
17+
derived from this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
-->
30+
<project name="schooner_memcached_client" default="jar" basedir=".">
31+
<property file="build.properties" />
32+
<path id="emma.lib">
33+
<pathelement location="${emma.dir}/emma.jar" />
34+
<pathelement location="${emma.dir}/emma_ant.jar" />
35+
</path>
36+
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
37+
<path id="test.classpath">
38+
<pathelement location="${junit.jar}" />
39+
<pathelement location="${log4j.jar}" />
40+
</path>
41+
<target name="clean">
42+
<delete dir="${build.dir}" />
43+
<delete dir="${test.build.dir}" />
44+
</target>
45+
46+
<!-- compilation target for packeging operations -->
47+
<target name="compile" depends="clean">
48+
<mkdir dir="${build.dir}" />
49+
<mkdir dir="${test.build.dir}" />
50+
<javac optimize="yes" srcdir="${src.dir}" destdir="${build.dir}" deprecation="true" target="1.5" source="1.5" nowarn="true" />
51+
<javac optimize="yes" srcdir="${test.dir}" destdir="${test.build.dir}" deprecation="true" target="1.5" source="1.5" nowarn="true">
52+
<classpath refid="test.classpath" />
53+
<classpath path="${build.dir}" />
54+
</javac>
55+
</target>
56+
57+
<target name="jar">
58+
<antcall target="clean" />
59+
<antcall target="compile" />
60+
<jar jarfile="${project}_${ver}.jar">
61+
<fileset dir="${build.dir}">
62+
<include name="com/schooner/MemCached/**/*" />
63+
<include name="com/danga/MemCached/**/*" />
64+
</fileset>
65+
</jar>
66+
<jar jarfile="${project}_test_${ver}.jar">
67+
<fileset dir="${test.build.dir}">
68+
<include name="com/schooner/MemCached/**/*" />
69+
<include name="com/danga/MemCached/**/*" />
70+
</fileset>
71+
</jar>
72+
<antcall target="clean" />
73+
</target>
74+
75+
<target name="runTest" depends="compile">
76+
<emma enabled="${emma.enabled}">
77+
<instr instrpath="${build.dir}" metadatafile="${report.dir}/metadata.emma" mode="overwrite">
78+
<filter value="+com.schooner.MemCached.*, -com.schooner.MemCached.*Test*, -com.danga.MemCached.*" />
79+
</instr>
80+
</emma>
81+
<junit printsummary="yes" showoutput="true" fork="true">
82+
<classpath>
83+
<pathelement location="${build.dir}" />
84+
<pathelement location="${test.build.dir}" />
85+
<path refid="emma.lib" />
86+
<path refid="test.classpath" />
87+
</classpath>
88+
<jvmarg value="-Dmemcached.host=${memcached.host}" />
89+
<jvmarg value="-Demma.coverage.out.file=${report.dir}/coverage.emma" />
90+
<jvmarg value="-Demma.coverage.out.merge=true" />
91+
<formatter type="xml" />
92+
<test name="com.schooner.MemCached.MemCachedClientAsciiTest" todir="${report.dir}" />
93+
<!--Enable the binary protocol unit test by uncomment the following line.
94+
Memcached binary protocol is supported by memcached 1.4+.
95+
Make sure the server is ready before starting these tests.
96+
You can specify the memcached host in the build.properties file in the same folder.
97+
-->
98+
<test name="com.schooner.MemCached.MemCachedClientBinaryTest" todir="${report.dir}" />
99+
<test name="com.schooner.MemCached.MemcachedClientUDPTest" todir="${report.dir}" />
100+
<test name="com.schooner.MemCached.OtherTest" todir="${report.dir}" />
101+
<test name="com.schooner.MemCached.WhalinScenarioTest" todir="${report.dir}" />
102+
</junit>
103+
<junitreport todir="${report.dir}">
104+
<fileset dir="${report.dir}">
105+
<include name="TEST-*.xml" />
106+
</fileset>
107+
<report format="frames" todir="${report.dir}" />
108+
</junitreport>
109+
<emma enabled="${emma.enabled}">
110+
<report sourcepath="${src.dir}">
111+
<fileset dir="${report.dir}">
112+
<include name="*.emma" />
113+
</fileset>
114+
<txt outfile="${report.dir}/coverage.txt" />
115+
<html outfile="${report.dir}/coverage.html" />
116+
</report>
117+
</emma>
118+
</target>
119+
120+
<target name="checkJavadoc">
121+
<available file="javadoc" property="javadoc.present" />
122+
</target>
123+
124+
<target name="checkReport">
125+
<available file="${report.dir}" property="report.present" />
126+
</target>
127+
128+
<target name="removeJavadoc" depends="checkJavadoc" if="javadoc.present">
129+
<delete>
130+
<fileset dir="javadoc">
131+
<include name="*" />
132+
</fileset>
133+
</delete>
134+
</target>
135+
<target name="removeReport" depends="checkReport" if="report.present">
136+
<delete>
137+
<fileset dir="${report.dir}">
138+
<include name="*" />
139+
</fileset>
140+
</delete>
141+
</target>
142+
143+
<target name="all">
144+
<delete>
145+
<fileset dir=".">
146+
<include name="*.jar" />
147+
<include name="*.zip" />
148+
</fileset>
149+
</delete>
150+
<antcall target="removeJavadoc" />
151+
<antcall target="removeReport" />
152+
<antcall target="runTest" />
153+
<antcall target="jar" />
154+
<antcall target="sourceDist" />
155+
<antcall target="javadoc" />
156+
</target>
157+
<target name="sourceDist">
158+
<mkdir dir="${project}_${ver}" />
159+
<copy todir="${project}_${ver}">
160+
<fileset dir=".">
161+
<include name="src/**/*" />
162+
<include name="doc/**/*" />
163+
<include name="lib/**/*" />
164+
<include name="report/**/*" />
165+
<include name=".*" />
166+
<include name="*.xml" />
167+
<include name="*.properties" />
168+
<include name="*.cld" />
169+
</fileset>
170+
</copy>
171+
<zip destfile="${project}_src_${ver}.zip" basedir=".">
172+
<include name="${project}_${ver}/**/*" />
173+
</zip>
174+
<delete dir="${project}_${ver}" />
175+
</target>
176+
<target name="javadoc">
177+
<javadoc access="public" author="true" classpath="lib/junit.jar" destdir="javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="com.schooner.MemCached,com.schooner.MemCached.command,com.danga.MemCached" source="1.5" sourcepath="src/main" splitindex="true" use="true" version="true" />
178+
</target>
179+
<target name="release">
180+
<antcall target="jar" />
181+
<antcall target="javadoc" />
182+
<zip destfile="${project}_${ver}.zip" basedir=".">
183+
<include name="${project}_${ver}/**/*" />
184+
<include name="javadoc" />
185+
<include name="${project}_${ver}.jar" />
186+
<include name="src/**/*" />
187+
<include name="doc/**/*" />
188+
<include name="lib/**/*" />
189+
<include name="report/**/*" />
190+
<include name="*.xml" />
191+
<include name="*.properties" />
192+
<include name="*.cld" />
193+
<include name="*.classpath" />
194+
<include name="*.project" />
195+
</zip>
196+
<delete dir="${project}_${ver}" />
197+
<delete dir="javadoc" />
198+
<delete file="${project}_${ver}.jar" />
199+
<delete file="${project}_test_${ver}.jar" />
200+
</target>
201+
</project>

src/main/com/schooner/MemCached/SchoonerSockIOPool.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ protected final SchoonerSockIO createSocket(String host) {
388388
}
389389
} catch (Exception ex) {
390390
log.error("++++ failed to get SockIO obj for: " + host);
391-
log.error(ex.getMessage(), ex);
391+
//log.error(ex.getMessage(), ex);
392392
socket = null;
393393
}
394394

@@ -540,7 +540,6 @@ public final SchoonerSockIO getConnection(String host) {
540540
ConcurrentLinkedQueue<SchoonerSockIO> sockets = socketPool.get(host);
541541
SchoonerSockIO socket = sockets.poll();
542542
if (socket == null) {
543-
System.out.println(poolCurrentConn.get(host).get());
544543
if (poolCurrentConn.get(host).get() < maxConn) {
545544
socket = createSocketWithAdd(host);
546545
} else {

0 commit comments

Comments
 (0)