Batch commit throws ServiceUnavailable: 503 Backend Error
See below:
OPERATING SYSTEM
$ uname -mrs Linux 3.19.5-100.fc20.x86_64 x86_64
ENVIRONMENT VARIABLES
PYTHON 2.7
export PYTHONHOME=/usr/bin/python2.7
export PYTHONPATH=/usr/lib/python2.7/site-packages
PYTHON modules for GCP
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/bin export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/lib export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/lib/googlecloudsdk export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/lib/googlecloudsdk/gcloud export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/lib/googlecloudapis
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/bq
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/gcutil
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/gcutil/lib
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/gsutil
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/gsutil/gslib
export PYTHONPATH=$PYTHONPATH:/home/charles/google-cloud-sdkgoogle-cloud-sdk/platform/gsutil/third_party
export PATH=$PATH:$PYTHONHOME
export PATH=$PATH:$PYTHONPATH
Google AppEngine SDK
export PATH=$PATH:/home/charles/google_appengine/
Google Cloud SDK
export CLOUDSDK_CONFIG=/home/charles/.config/gcloud export CLOUDSDK_PYTHON=/usr/bin/python2.7 export CLOUDSDK_PYTHON_SITEPACKAGES=1
BOTO
export BOTO_CONFIG=/home/charles/.boto
export NVM_DIR="/home/charles/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
The next line updates PATH for the Google Cloud SDK.
source '/home/charles/google-cloud-sdk/path.bash.inc'
The next line enables bash completion for gcloud.
source '/home/charles/google-cloud-sdk/completion.bash.inc'
FORM OF AUTHENTICATION
The credentialed account being used is the owner of the Google project, for which Cloud Datastore API is enabled.
PYTHON CODE
from gcloud import storage storage.set_default_bucket('') storage.set_default_project(_PROJECT_NAME) from gcloud import datastore datastore.set_default_dataset_id(_DATA_SET_ID)
datastore.set_defaults(namespace=_NAMESPACE)
from gcloud.datastore.batch import Batch
import traceback
def Load_Datastore():
try:
Get_Bucket_Metadata()
#set configuration variables
storage_conn = storage.get_connection()
storage.set_default_connection(storage_conn)
datastore_conn = datastore.get_connection()
datastore.set_default_connection(datastore_conn)
for _BUCKET_NAME in _BUCKET_LIST:
print "Bucket Name: %s" % (_BUCKET_NAME)
.
.
.
#an empty list is false
if not _RECORDS:
print "_RECORDS is empty"
else:
print "there are %s records to write into Datastore"%(str(len(_RECORDS)))
with datastore.batch.Batch(connection=datastore_conn) as batch:
_ENTITIES=[]
for _RECORD in _RECORDS:
_PROPERTIES=[]
if _RECORD:
for _KEY_VALUES in _RECORD:
_KEY_VALUE_PAIR=_KEY_VALUES.split('|')
if str(_KEY_VALUE_PAIR[0])=='ROW_KEY':
_ENTITY_KEY=str(_KEY_VALUE_PAIR[1])
else:
_PROPERTIES.append("%s|%s"%(str(_KEY_VALUE_PAIR[0]),str(_KEY_VALUE_PAIR[1])))
if not _PROPERTIES:
print "_PROPERTIES is empty"
else:
try:
key = datastore.Key(_SOURCE_TABLE_NAME.upper(),_ENTITY_KEY,namespace=_NAMESPACE,dataset_id=_DATA_SET_ID)
try:
DS_ENTITY = datastore.Entity(key)
for _PROPERTY in _PROPERTIES:
_NAME_VALUE=_PROPERTY.split('|')
_COLUMN_NAME=str(_NAME_VALUE[0])
_COLUMN_VALUE=str(_NAME_VALUE[1])
DS_ENTITY.update({_COLUMN_NAME:_COLUMN_VALUE})
# Now let's save it to our datastore:
_ENTITIES.append(DS_ENTITY)
except Exception, inst:
print "datastore.Entity(%s) Unexpected error: %s"%(str(_ENTITY_KEY),str(sys.exc_info()[0]))
if isinstance(inst,ValueError):
print "ValueError: %s"%(inst.message)
if isinstance(inst,AttributeError):
print "AttributeError: %s"%(inst.message)
except Exception, inst:
print "datastore.Key(_SOURCE_TABLE_NAME,_ENTITY_KEY,_NAMESPACE,_DATASET_ID Unexpected error: %s"%(str(sys.exc_info()[0]))
if isinstance(inst,ValueError):
print "ValueError: %s"%(inst.message)
if isinstance(inst,AttributeError):
print "AttributeError: %s"%(inst.message)
for _ENTITY in _ENTITIES:
batch.put(_ENTITY)
print 'batch.put(_ENTITY)'
except Exception, inst:
print '\nLoad_Datastore() Unexpected error: ' + str(sys.exc_info()[0])
if isinstance(inst,ValueError):
print "ValueError: %s\n"%(inst.message)
if isinstance(inst,AttributeError):
print "AttributeError: %s\n"%(inst.message)
if isinstance(inst,TypeError):
print "TypeError: %s\n"%(inst.message)
print '-'*60
traceback.print_exc(file=sys.stdout)
print '-'*60
raise
STACK TRACE
Load_Datastore() Unexpected error: <class 'gcloud.exceptions.ServiceUnavailable'>
Traceback (most recent call last): File "/home/charles/workspace_Python/HBaseSchemaFromXML/pkg1/datastore_loader.py", line 326, in Load_Datastore print 'batch.put(_ENTITY)' File "/usr/lib/python2.7/site-packages/gcloud-0.5.0-py2.7.egg/gcloud/datastore/batch.py", line 232, in exit self.commit() File "/usr/lib/python2.7/site-packages/gcloud-0.5.0-py2.7.egg/gcloud/datastore/batch.py", line 207, in commit response = self.connection.commit(self._dataset_id, self.mutation) File "/usr/lib/python2.7/site-packages/gcloud-0.5.0-py2.7.egg/gcloud/datastore/connection.py", line 324, in commit datastore_pb.CommitResponse) File "/usr/lib/python2.7/site-packages/gcloud-0.5.0-py2.7.egg/gcloud/datastore/connection.py", line 108, in _rpc data=request_pb.SerializeToString()) File "/usr/lib/python2.7/site-packages/gcloud-0.5.0-py2.7.egg/gcloud/datastore/connection.py", line 85, in _request raise make_exception(headers, content, use_json=False)
ServiceUnavailable: 503 Backend Error
Unexpected error: <class 'gcloud.exceptions.ServiceUnavailable'> Exception instance type: <class 'gcloud.exceptions.ServiceUnavailable'> done.
Ran 0 tests in 0.000s
NOTES
The script executes all of the batch.put() statements, and then throws the above error after the 'when' clause finishes.
Any suggestions on how to fix this bug are appreciated
feel free to share the doc here and we'll send it along :)
I will, just as soon as I figure out how to build out my Linux laptop so that it can run Python scripts which interact with GCS and with Google BigQuery.
I now have a script which reads from GCS buckets and parses and loads 1000s of CSV files into Google Cloud Datastore. The parser is governed by a metadata rules engine/method that re-creates the source schema within Datastore.
I still have to figure out, by 9am tomorrow morning, how to read 1000s of those same CSVs and load them into BigQuery, and have the BigQuery schema likewise conform to the source schema.
Another fun weekend.
On Sun, May 10, 2015 at 11:24 AM, JJ Geewax [email protected] wrote:
feel free to share the doc here and we'll send it along :)
— Reply to this email directly or view it on GitHub https://github.com/GoogleCloudPlatform/gcloud-python/issues/866#issuecomment-100671177 .
Charles B. Clifford (720) 842-7251