2013-09-07 17:41:31 -04:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
__all__ = ["StorageLevel"]
|
|
|
|
|
2014-07-22 01:30:53 -04:00
|
|
|
|
2014-09-08 18:45:28 -04:00
|
|
|
class StorageLevel(object):
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2013-09-07 17:41:31 -04:00
|
|
|
"""
|
|
|
|
Flags for controlling the storage of an RDD. Each StorageLevel records whether to use memory,
|
|
|
|
whether to drop the RDD to disk if it falls out of memory, whether to keep the data in memory
|
2015-12-18 23:06:05 -05:00
|
|
|
in a JAVA-specific serialized format, and whether to replicate the RDD partitions on multiple
|
|
|
|
nodes. Also contains static constants for some commonly used storage levels, MEMORY_ONLY.
|
|
|
|
Since the data is always serialized on the Python side, all the constants use the serialized
|
|
|
|
formats.
|
2013-09-07 17:41:31 -04:00
|
|
|
"""
|
|
|
|
|
2014-07-22 01:30:53 -04:00
|
|
|
def __init__(self, useDisk, useMemory, useOffHeap, deserialized, replication=1):
|
2013-09-07 17:41:31 -04:00
|
|
|
self.useDisk = useDisk
|
|
|
|
self.useMemory = useMemory
|
2014-04-04 23:36:24 -04:00
|
|
|
self.useOffHeap = useOffHeap
|
2013-09-07 17:41:31 -04:00
|
|
|
self.deserialized = deserialized
|
|
|
|
self.replication = replication
|
|
|
|
|
2014-03-12 02:57:05 -04:00
|
|
|
def __repr__(self):
|
2014-04-04 23:36:24 -04:00
|
|
|
return "StorageLevel(%s, %s, %s, %s, %s)" % (
|
|
|
|
self.useDisk, self.useMemory, self.useOffHeap, self.deserialized, self.replication)
|
2014-03-12 02:57:05 -04:00
|
|
|
|
2014-06-17 02:31:31 -04:00
|
|
|
def __str__(self):
|
|
|
|
result = ""
|
|
|
|
result += "Disk " if self.useDisk else ""
|
|
|
|
result += "Memory " if self.useMemory else ""
|
2016-04-02 20:55:46 -04:00
|
|
|
result += "OffHeap " if self.useOffHeap else ""
|
2014-06-17 02:31:31 -04:00
|
|
|
result += "Deserialized " if self.deserialized else "Serialized "
|
|
|
|
result += "%sx Replicated" % self.replication
|
|
|
|
return result
|
|
|
|
|
2014-04-04 23:36:24 -04:00
|
|
|
StorageLevel.DISK_ONLY = StorageLevel(True, False, False, False)
|
|
|
|
StorageLevel.DISK_ONLY_2 = StorageLevel(True, False, False, False, 2)
|
2020-08-10 10:33:06 -04:00
|
|
|
StorageLevel.DISK_ONLY_3 = StorageLevel(True, False, False, False, 3)
|
2015-12-18 23:06:05 -05:00
|
|
|
StorageLevel.MEMORY_ONLY = StorageLevel(False, True, False, False)
|
|
|
|
StorageLevel.MEMORY_ONLY_2 = StorageLevel(False, True, False, False, 2)
|
|
|
|
StorageLevel.MEMORY_AND_DISK = StorageLevel(True, True, False, False)
|
|
|
|
StorageLevel.MEMORY_AND_DISK_2 = StorageLevel(True, True, False, False, 2)
|
2016-04-13 02:06:55 -04:00
|
|
|
StorageLevel.OFF_HEAP = StorageLevel(True, True, True, False, 1)
|
2020-09-15 09:41:22 -04:00
|
|
|
StorageLevel.MEMORY_AND_DISK_DESER = StorageLevel(True, True, False, True)
|